Deserializing an entire XML structure to class instances

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ullner
    New Member
    • Mar 2008
    • 4

    Deserializing an entire XML structure to class instances

    I have an XML fil that looks like this:

    Code:
    <Environment>
        <AreaOfInterest>
          <Name>ScenarioMap</Name>
          <UpperRight>
            <GDC>
              <Latitude>-179</Latitude>
              <Longitude>-179</Longitude>
              <ElevationAGL>0</ElevationAGL>
            </GDC>
          </UpperRight>
          <LowerLeft>
            <GDC>
              <Latitude>180</Latitude>
              <Longitude>180</Longitude>
              <ElevationAGL>0</ElevationAGL>
            </GDC>
          </LowerLeft>
        </AreaOfInterest>
      </Environment>
    Currently, I'm deserializing the code as follows;
    Code:
                    XmlNode xmlnode = doc.SelectSingleNode("//Environment");
                    XmlSerializer ser = new XmlSerializer(typeof(Environment));
                    XmlNodeReader reader = new XmlNodeReader(xmlnode);
                    Environment en = (Environment)ser.Deserialize(reader);
    (And it goes on for each node...)

    So I'm deserializing each node by themselves. However, I'd like to deserialize the entire XML without having to hard code which class name and which node I want to deserialize. How can I accomplish this? Also, the XML might (it might not) have multiple occurances of a similar named node, as seen above.
Working...