tags:

views:

134

answers:

3

I have to read the XML:

<items>
    <item>
      <prop1>value1</prop1>
      <prop2>value2</prop2>
      <prop3>value3</prop3>
    </item>
    <item>
      <prop1>value1</prop1>
      <prop2>value2</prop2>
      <prop3>value3</prop3>
    </item>
</items>

And put the values into a List<CLASS>.

Some options:

  • Use XMLSerializer to deserialize to a List
  • Use XMLDocument to read each item using SelectNodes with XPath and put the values into a List
  • Use XMLReader to read each node and put the values into a List
  • Other option...
+6  A: 

By far the fastest that I have seen is to use XSD.exe to create an XSD and Class to go with it, then use serialization.

Mitchel Sellers
+1  A: 

Another option would be to use LinqToXml.

Dan Diplo
A: 

If you're in dotnet, install the WCF starter pack. Then you'll have an option "Paste XML as Types", so you can cut the XML you're looking to serialize into the clipboard and paste it into code as a serializable type. Then you can just serialize the XML and get the values through the class.

NickAtuShip