Deserializing - Can this be done?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • SteveT

    Deserializing - Can this be done?

    I want to be able to deserialize data contained within a XML file to a data
    structure. This I know how to do. However, what I want to be able to do is
    the following:
    1. Serialize multiple "C# classes" into a single XML file. One at a time.
    2. Deserialize each "C# class" from the XML file. One at a time.

    Is this possible? I don't see a way to do this. If it isn't possible does
    anyone have a suggestion on how to get around a problem I have. I have many
    data structures that I need to save to disk and later retrieve when a program
    runs. The data structures are contained in nodes of a TreeView list. If I
    serialize each structure one-by-one I may have hundreds of XML files. I want
    to group certain TreeView node-paths all under a single XML file to have
    fewer XML files to manage and thus make things easier. How could I go about
    doing this?
    --
    -----------
    Thanks,
    Steve
  • sloan

    #2
    Re: Deserializing - Can this be done?




    Maybe you can get some ideas here
    9/21/2005
    XmlSerializatio n with IDictionary and CollectionBase Objects



    But for
    #1
    I'd write a "wrapper" object to handle this. Like, if you needed to
    serialize a Plant object, Person object, Animal object......... you could
    create a
    ThingWrapper class, with 3 properties (1 for a Plant, 1 for a Person, 1 for
    an Animal), and serialize the ThingWrapper.
    OR
    You can do each thing individually, and roll your own "xml merger", but
    you'd have to do alot of work here. And when you needed to pull them out,
    you'd have to use SelectNodes or SelectSingleNod e, and get the innerXml to
    serialize each object. This is why I mention the ThingWrapper above.

    #2 related to #1.

    Check out my blog code...........

    But the ThingWrapper is where I'd look to. That, or using the blog code to
    figure out how to serialize collections of objects.






    "SteveT" <SteveT@newsgro ups.nospamwrote in message
    news:622FB345-9AE6-48BE-9AD6-6DBC0378BC48@mi crosoft.com...
    I want to be able to deserialize data contained within a XML file to a
    data
    structure. This I know how to do. However, what I want to be able to do
    is
    the following:
    1. Serialize multiple "C# classes" into a single XML file. One at a time.
    2. Deserialize each "C# class" from the XML file. One at a time.
    >
    Is this possible? I don't see a way to do this. If it isn't possible
    does
    anyone have a suggestion on how to get around a problem I have. I have
    many
    data structures that I need to save to disk and later retrieve when a
    program
    runs. The data structures are contained in nodes of a TreeView list. If
    I
    serialize each structure one-by-one I may have hundreds of XML files. I
    want
    to group certain TreeView node-paths all under a single XML file to have
    fewer XML files to manage and thus make things easier. How could I go
    about
    doing this?
    --
    -----------
    Thanks,
    Steve

    Comment

    • Kevin Spencer

      #3
      Re: Deserializing - Can this be done?

      You can put them into a Generic Collection, and serialize the Collection.

      --
      HTH,

      Kevin Spencer
      Microsoft MVP
      Chicken Salad Shooter
      Thoughts and Ideas about programming, philosophy, science, arts, life, God, and related subjects.


      A man, a plan, a canal, a palindrome that has.. oh, never mind.

      "SteveT" <SteveT@newsgro ups.nospamwrote in message
      news:622FB345-9AE6-48BE-9AD6-6DBC0378BC48@mi crosoft.com...
      >I want to be able to deserialize data contained within a XML file to a data
      structure. This I know how to do. However, what I want to be able to do
      is
      the following:
      1. Serialize multiple "C# classes" into a single XML file. One at a time.
      2. Deserialize each "C# class" from the XML file. One at a time.
      >
      Is this possible? I don't see a way to do this. If it isn't possible
      does
      anyone have a suggestion on how to get around a problem I have. I have
      many
      data structures that I need to save to disk and later retrieve when a
      program
      runs. The data structures are contained in nodes of a TreeView list. If
      I
      serialize each structure one-by-one I may have hundreds of XML files. I
      want
      to group certain TreeView node-paths all under a single XML file to have
      fewer XML files to manage and thus make things easier. How could I go
      about
      doing this?
      --
      -----------
      Thanks,
      Steve

      Comment

      • SteveT

        #4
        Re: Deserializing - Can this be done?

        Great minds must think alike! :) Sloan's first comment got me to thinking
        that an array of these objects could be written to an XML file. I just
        completed the test code and sure enough it works.

        Thanks to you both.
        --
        -----------
        Thanks,
        Steve


        "Kevin Spencer" wrote:
        You can put them into a Generic Collection, and serialize the Collection.
        >
        --
        HTH,
        >
        Kevin Spencer
        Microsoft MVP
        Chicken Salad Shooter
        Thoughts and Ideas about programming, philosophy, science, arts, life, God, and related subjects.

        >
        A man, a plan, a canal, a palindrome that has.. oh, never mind.
        >
        "SteveT" <SteveT@newsgro ups.nospamwrote in message
        news:622FB345-9AE6-48BE-9AD6-6DBC0378BC48@mi crosoft.com...
        I want to be able to deserialize data contained within a XML file to a data
        structure. This I know how to do. However, what I want to be able to do
        is
        the following:
        1. Serialize multiple "C# classes" into a single XML file. One at a time.
        2. Deserialize each "C# class" from the XML file. One at a time.

        Is this possible? I don't see a way to do this. If it isn't possible
        does
        anyone have a suggestion on how to get around a problem I have. I have
        many
        data structures that I need to save to disk and later retrieve when a
        program
        runs. The data structures are contained in nodes of a TreeView list. If
        I
        serialize each structure one-by-one I may have hundreds of XML files. I
        want
        to group certain TreeView node-paths all under a single XML file to have
        fewer XML files to manage and thus make things easier. How could I go
        about
        doing this?
        --
        -----------
        Thanks,
        Steve
        >
        >
        >

        Comment

        Working...