I have a xml file and I have to store the values in the list to use it later.
The xml file contain mostly ints and string
s and it looks like this:
<AllThings>
<Anythings>
<Anything Step="1" Name="1">
<Somethings>
<Something Id="10">
<Things>
<Thing Id="11">abc</Thing>
<Thing Id="12">123</Thing>
</Things>
</Something>
<Something Id="20">
<Things>
<Thing Id="21">cde</Thing>
<Thing Id="22">345</Thing>
</Things>
</Something>
<Something Id="30">
<Things>
<Thing Id="31">efg</Thing>
<Thing Id="32">567</Thing>
</Things>
</Something>
<Something Id="40">
<Things>
<Thing Id="41">ghi</Thing>
<Thing Id="42">789</Thing>
</Things>
</Something>
</Somethings>
</Anything>
<Anything Step="2" Name="2">
<Somethings>
<Something Id="10">
<Things>
<Thing Id="11">aaa</Thing>
<Thing Id="12">111</Thing>
</Things>
</Something>
<Something Id="20">
<Things>
<Thing Id="21">ccc</Thing>
<Thing Id="22">333</Thing>
</Things>
</Something>
<Something Id="30">
<Things>
<Thing Id="31">eee</Thing>
<Thing Id="32">555</Thing>
</Things>
</Something>
<Something Id="40">
<Things>
<Thing Id="41">ggg</Thing>
<Thing Id="42">777</Thing>
</Things>
</Something>
</Somethings>
</Anything>
</Anythings>
</AllThings>
What is the best way to get the values from this kind of xml and store it in the list(s)?
I've tried with using System.Xml;
to create a reader and make reader.ReadToFollowing("Something")
in combination with reader.GetAttribute("Id")
, but it hasn`t gone deep enough.
In most tutorials the xml is like:
<Animal type="cat">
<Name>Bob</Name>
<Age>8</Age>
</Animal>
and there it works