How to read xml node names using C# -


i new area. please let me know how can or display

bookstore, book, title, price (distinct output needed)

from following xml file, how can read , print distinct xml nodes.

<?xml version="1.0" encoding="utf-8"?>  <bookstore>   <book>     <title lang="en">harry potter</title>     <price>29.99</price>   </book>    <book>     <title lang="en">learning xml</title>     <price>39.95</price>   </book> </bookstore> 

it's easy linq xml:

var xdoc = xdocument.load(filename); var names = xdoc.descendants() // elements xml                 .select(e => e.name.localname) // select local name of each element                 .distinct(); // pick distinct names 

for sample xml output is

[   "bookstore",   "book",   "title",   "price" ] 

descendants() same xpathselectelements("//*")


Comments