c# - xml loading with specific filter -


i have xml format this..

<root>     <bookstore>         <name>xxxxxx</bunit>     </bookstore>     <book>         <id>000000000000001001</id>         <title>everyday italian</title>         <author>giada de laurentiis</author>         <year>2005</year>         <price>30.00</price>             </book>     <book>         <id>000000000000001002</id>         <title>everyday italian</title>         <author>giada de laurentiis</author>         <year>2005</year>         <price>30.00</price>             </book>     <book>         <id>000000000000001003</id>         <title>everyday italian</title>         <author>giada de laurentiis</author>         <year>2005</year>         <price>30.00</price>             </book>     <book>         <id>000000000000001004</id>         <title>everyday italian</title>         <author>giada de laurentiis</author>         <year>2005</year>         <price>30.00</price>             </book> </root> 

now want load single node of book "id" without loop. have tried this.. full node of book(first item id=000000000000001001) below line

_nodelist = objxml.selectsinglenode("//book/")  

but give id filter below code.

_nodelist = objxml.selectsinglenode("//book/id['000000000000001001']") 

and need full book node particular id.

if i've understood question correctly, want select book element child element id value?

if case can use simple linq query return book node id (assuming have corrected xml first):

var book = n in xml.descendants("root").elements("book")                        n.element("id").value == "000000000000001001"                        select n; 

you project values anonymous types , cast query list enumerate results:

var book = (from n in xml.descendants("root").elements("book")             n.element("id").value == "000000000000001001"             select new             {                 id = (string)n.element("id").value,                 title = (string)n.element("title").value,                 author = (string)n.element("author").value,                 year = (string)n.element("year").value,                 price = (string)n.element("price").value             }).tolist(); 

which give output such as:

enter image description here


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -