Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / September 2005

Tip: Looking for answers? Try searching our database.

XmlSerialization of an array of objects.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Kevin Burton - 08 Sep 2005 03:14 GMT
I have some code that serializes an array of objects:

   XmlSerializer serializer = new XmlSerializer(typeof(Purchase[]));
   XmlTextWriter w = new XmlTextWriter("vpurchase.xml", Encoding.UTF8);
   serializer.Serialize(w, purchaseArray);

This gives me something like:

<ArrayOfPurchase>
 <Purchase> . . . </Purchase>
 <Purchase> . . . </Purchase>
</ArrayOfPurchase>

Now if I try to deserialize the file with:

   XmlSerializer serializer = new XmlSerializer(typeof(Purchase));
   XmlTextReader r = new XmlTextReader("vpurchase.xml");
   Purchase [] purchaseArray = (Purchase [])serializer.Deserialize(r);

I get an error. Somehow my theory is that the <ArrayOfPurchase> token is not
being recognized properly in deserialization. How can I get this to work
bidirectionallly?

Thank you.

Kevin
Oliver Sturm - 08 Sep 2005 10:23 GMT
>I have some code that serializes an array of objects:
>
[quoted text clipped - 16 lines]
>
>I get an error.

Which is?

>Somehow my theory is that the <ArrayOfPurchase> token is not
>being recognized properly in deserialization. How can I get this to work
>bidirectionallly?

I haven't tried your code just now, but if you are actually using these
exact lines you posted, you're passing in the wrong type to the serializer
when loading. It should be Purchase[], not Purchase.

Would be better to post this kind of question to ...dotnet.xml, by the way.

               Oliver Sturm
Signature

Expert programming and consulting services available
See http://www.sturmnet.org (try /blog as well)


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.