dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: serializing objects to XML

  1. #1
    Join Date
    May 2001
    Location
    Silicon Valley
    Posts
    113

    Question serializing objects to XML

    Folks,

    Is it possible to achieve random access with XmlSerializer? I would like to be able able to store multiple objects of different types in the same XML file (adding them at different times, not all at once). I would like to be able to de-serialize them one at a time. I would like to update them one at a time.

    Is XmlSerializer a right kind of tool for this?
    Is there something better (short of setting up a proper database)?
    Am I looking for something that goes by a different name?

    Any suggestion, insight or reference is really appreciated!

    - Nick

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,248

    Re: serializing objects to XML

    Will the types be known ahead of time or do you want to randomly add items of different types?

  3. #3
    Join Date
    May 2001
    Location
    Silicon Valley
    Posts
    113

    Re: serializing objects to XML

    Quote Originally Posted by Arjay View Post
    Will the types be known ahead of time or do you want to randomly add items of different types?
    The types will not be known in advance. That's the reason why XmlSerializer looks appealing. I can extract the type information, so I shouldn't need to know it ahead of time
    Code:
    XmlSerializer xmlSerializer = new XmlSerializer(braveNewObject.GetType());
    I have picked up that thought here: Serialize multiple objects of different types into single XML using XDocument

    Of course, there may be other options, which I'm not even aware of, which are just as nice.
    Last edited by kender_a; February 22nd, 2015 at 08:40 PM.

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,248

    Re: serializing objects to XML

    Serializing unknown types into xml won't be a problem; however, to deserialize the xml back into objects, you need to know what the objects will be.

    If you structure your xml correctly, you can effectively store the data as different 'objects', but in actuality, the underlying types need to be known during deserialization.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)