> Can any one help me
I can make it work. Please see " // HERE____" in your code. Now it compiles
and runs.
This line gives you the internal error:
/** @attribute XmlElement(Type = Manager.class) * */
public Employee Manager;
Change it to:
/** @attribute XmlElement(Manager.class, ElementName = "Manager") */
public Employee Manager;
You have a few extra problems too I corrected for you. =:o)
import System.*;
import System.Collections.*;
import System.IO.*;
import System.Xml.Serialization.*;
public class Group
{
/** @attribute XmlElement(ElementName = "Members", Namespace =
http://www.cpandl.com) */
public Employee Employees[];
/** @attribute XmlElement(DataType = "double", ElementName = "Building")
*/
public double GroupID;
/** @attribute XmlElement(DataType = "hexBinary") */
public ubyte HexBytes[];
/** @attribute XmlElement(DataType = "boolean") */
public boolean IsActive;
// HERE_____________
/** @attribute XmlElement(Manager.class, ElementName = "Manager") */
public Employee Manager;
// _________________
/** @attribute XmlElement(int.class, ElementName = "ObjectNumber")
* @attribute XmlElement(String.class, ElementName = "ObjectString") */
public ArrayList ExtraInfo;
} //Group
public class Employee
{
public String Name;
} //Employee
public class Manager extends Employee
{
public int Level;
} //Manager
public class Runq
{
public void SerializeObject(String filename)
{
// Create the XmlSerializer.
XmlSerializer s = new XmlSerializer(Group.class.ToType());
// To write the file, a TextWriter is required.
TextWriter writer = new StreamWriter(filename);
/* Create an instance of the group to serialize, and set its
properties. */
Group group = new Group();
group.GroupID = 10.089;
group.IsActive = false;
group.HexBytes = new ubyte[]{Convert.ToByte(100)};
Employee x = new Employee();
Employee y = new Employee();
// HERE_______
x.Name = new String("Jack");
y.Name = new String("Jill");
// ___________
group.Employees = new Employee[]{x, y};
Manager mgr = new Manager();
// HERE _____
mgr.Name = new String("Sara");
// __________
mgr.Level = 4;
group.Manager = mgr;
/* Add a number and a string to the ArrayList returned by the
ExtraInfo property. */
group.ExtraInfo = new ArrayList();
// HERE________
group.ExtraInfo.Add( (System.Int32)(42) );
group.ExtraInfo.Add("Answer");
// ____________
// Serialize the object, and close the TextWriter.
// HERE____
try
{
s.Serialize(writer, group);
writer.Close();
}
catch ( System.InvalidOperationException invalid )
{
System.Console.WriteLine( "Exception: "+invalid);
}
// _______
} //SerializeObject
public void DeserializeObject(String filename)
{
FileStream fs = new FileStream(filename, FileMode.Open);
XmlSerializer x = new XmlSerializer(Group.class.ToType());
Group g = ((Group)(x.Deserialize(fs)));
Console.WriteLine(g.Manager.Name);
Console.WriteLine(g.GroupID);
Console.WriteLine(g.HexBytes.get_Item( 0));
for(int iCtr =0;iCtr < g.Employees.length;iCtr++)
{
Employee e = g.Employees[iCtr];
// HERE______
Console.WriteLine(e.Name);
// __________
}
} //DeserializeObject
public static void main(String[] args)
{
Runq test = new Runq();
test.SerializeObject("FirstDoc.xml");
test.DeserializeObject("FirstDoc.xml");
}
}
Regards,
Lars-Inge T?nnessen
www.larsinge.com
Diganta Roy[MSFT] - 08 Sep 2004 11:54 GMT
This issue has been fixed in Visual Studio .NET 2005 - currently its in
Beta1.
Note that you need to access the fields in the class Employee as x.Name and
not as x.get_Name() or x.set_Name; as "Name" is a field and not a property.
Thanks,
Diganta Roy
Microsoft Visual J# .NET Product Team
This posting is provided "AS IS" with no warranties, and confers no
rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
--------------------
>Reply-To: "Lars-Inge T?nnessen" <http://emailme.larsinge.com>
>From: "Lars-Inge T?nnessen" <http://emailme.larsinge.com>
[quoted text clipped - 10 lines]
>NNTP-Posting-Host: stud-064.vpn.uit.no 129.242.154.197
>Path:
cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10
.phx.gbl
>Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.vjsharp:5964
>X-Tomcat-NG: microsoft.public.dotnet.vjsharp
[quoted text clipped - 146 lines]
>Lars-Inge T?nnessen
>www.larsinge.com