tags:

views:

195

answers:

2
<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?

+2  A: 
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.

Dante
+1  A: 
var values = from e in XDocument.Load("MyFile.xml").Descendants("Balance")
             select e.Attribute("Value").Value;

foreach (var e in values)
{
    Console.WriteLine(e);
}
Yannick M.