c# - How do I perform this XPath query with Linq? -


In the following code I am using xpath to use all matching nodes to use xpath, and I'm adding StringBuilder values.

  stringbuilder sb = New stringbilder (); Foreach (The XmlNode node in the Data.SelectNodes ("ID / item [@ id = 200] / dat [1] / line [position ()> 1] / data [1] / text ()")) {sb. Append (node.Value); } Return sb.ToString ();  

How can I do the same thing except Linq instead of XML? Assume that in the new version, this is Data is a XElement object.

The query syntax will look something like this. From the items in the data

  var nodes. Elements ("Items"), where the items. Attribute ("id"). Value == "200" let's dat = item.Element ("DAT"). From the line in Dat.Elements ("line"). Skip (1) data = line. Select the element ("data") data; Var sb = new stringbilder (); Foreach (nodes in nodes) sb.Append (node.Value);  

... it will be free of potentially frustrated exceptions and will get rid of the foreach loop.

  var node = from the item in the data Elements ("item") id = item.Attribute ("id") where id! = Null & amp; Amp; Id.Value == "200" let = item.Element ("DAT") where dat. Leave the null in the line in dat.Elements ("line"). (1) Data = Row. Element ("data") where the data! = Select Zero Data value; Return nodes. Aggett (new stringbuilder (), (SB, R) => sb.Append (r)) ostring ();  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -