![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Reply-To: "Lars-Inge Tønnessen" <http://emailme.larsinge.com From: "Lars-Inge Tønnessen" <http://emailme.larsinge.com References: <98E31D6E-A45B-45CF-8459-99B6C5327602 (AT) microsoft (DOT) com Subject: Re: Internal Compiler Error Date: Tue, 27 Apr 2004 16:37:40 +0200 Lines: 160 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 Message-ID: <eJGEFVGLEHA.2976 (AT) TK2MSFTNGP10 (DOT) phx.gbl Newsgroups: microsoft.public.dotnet.vjsharp NNTP-Posting-Host: stud-064.vpn.uit.no 129.242.154.197 Path: cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFT NGP08.phx.gbl!TK2MSFTNGP10 |
|
Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.vjsharp:5964 X-Tomcat-NG: microsoft.public.dotnet.vjsharp 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. = )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 |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |