<PKT>
<Result Name="GetBalance" Success="1">
<Returnset>
<Balance Type="int" Value="0" />
</Returnset>
</Result>
</PKT>
Best way to get the value of Balance
with LINQ-to-XML?
<PKT>
<Result Name="GetBalance" Success="1">
<Returnset>
<Balance Type="int" Value="0" />
</Returnset>
</Result>
</PKT>
Best way to get the value of Balance
with LINQ-to-XML?
XDocument doc = XDocument.Load("MyFile.xml");
IEnumerable<XElement> elements = doc.Descendants("Balance");
foreach (XElement e in elements)
{
Console.Write(e.Attribute("Value").Value);
}
You can do it this way. I typed the code directly here, you may want to confirm any typos.
var values = from e in XDocument.Load("MyFile.xml").Descendants("Balance")
select e.Attribute("Value").Value;
foreach (var e in values)
{
Console.WriteLine(e);
}