I have a XML file like this and I want to read the ID, shortname, Name node value.
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<AccountingUnitList xmlns="http://www.google.com">
<AccountingUnit>
<ID>17406</ID>
<ShortName>test</ShortName>
<Name>test</Name>
</AccountingUnit>
<AccountingUnit>
<ID>18006</ID>
<ShortName>ANOTHERtest</ShortName>
<Name>Anothertest</Name>
</AccountingUnit>
<AccountingUnit>
<ID>18046</ID>
<ShortName>RKU</ShortName>
<Name>hospital</Name>
</AccountingUnit>
<AccountingUnit>
<ID>18047</ID>
<ShortName>MNU</ShortName>
<Name>MNU</Name>
</AccountingUnit>
</AccountingUnitList>
what is the best way to read the Node element recursively?
This is how I am trying to read the Node value:
var accountingunit = (
from e in XDocument.Parse(textresult).Root.Elements("AccountingUnit")
select new node
{
idvalue = (string)e.Element("ID"),
shortname =(string)e.Element("ShortName"),
name = (string)e.Element("Name"),
});
foreach(var unit in accountingunit)
{
Console.WriteLine("ID"+ unit.idvalue + unit.name + unit.shortname);
}
Here is the node consructor:
public class node
{
public string idvalue { get; set; }
public string shortname { get; set; }
public string name { get; set; }
}