0

Given the following XML structure:

<RootNode>
  <NodeA>
      <Value>1</Value>
      <Value>2</Value>
  <NodeA>
  <NodeB>
      <Value>100</Value>
      <Value>200</Value>
  <NodeB>
</RootNode>

How do I deserialize this to the following c# objects

List<NodeA> and List<NodeB>
Alex
  • 13,024
  • 33
  • 62
WorkInProgress
  • 393
  • 6
  • 16
  • possible duplicate of [Is it possible to deserialize XML into List?](http://stackoverflow.com/questions/608110/is-it-possible-to-deserialize-xml-into-listt) – Matthew Frontino Apr 09 '15 at 17:37
  • @MatthewFrontino I think the article you're linking to is misnamed... most of the answers involve serialization, not deserialization. – Kjata30 Apr 09 '15 at 17:40
  • 1
    @Kjata30 Hmm, I believe the question is answered as serialization because you use the same object map to do both serialization and deserialization. When you serialize your objects, you can use the same set classes to deserialize? (You __can__ use a different set of classes, but the attributes will need to still be mapped the same way) – Matthew Frontino Apr 09 '15 at 17:46

1 Answers1

0

Use XMLDocument.SelectNodes to create a new object for each child node you want to process, then use a generic method to create and cast a new C# object for each node.

See also: split xml document into chunks and How to Deserialize XML document.

Community
  • 1
  • 1
Kjata30
  • 721
  • 7
  • 20