How do I perform this XPath query with Linq?

Posted by John Hansen on Stack Overflow See other posts from Stack Overflow or by John Hansen
Published on 2010-06-15T19:26:43Z Indexed on 2010/06/15 19:52 UTC
Read the original article Hit count: 186

Filed under:
|

In the following code I am using XPath to find all of the matching nodes using XPath, and appending the values to a StringBuilder.

StringBuilder sb = new StringBuilder();
foreach (XmlNode node in this.Data.SelectNodes("ID/item[@id=200]/DAT[1]/line[position()>1]/data[1]/text()"))
{
    sb.Append(node.Value);
}
return sb.ToString();

How do I do the same thing, except using Linq to XML instead? Assume that in the new version, this.Data is an XElement object.

© Stack Overflow or respective owner

Related posts about c#

Related posts about linq-to-xml