I'd like to get all the element name from a xml file, for example the xml file is,
<BookStore> <BookStoreInfo> <Address /> <Tel /> <Fax /> <BookStoreInfo> <Book> <BookName /> <ISBN /> <PublishDate /> </Book> <Book> .... </Book> </BookStore>
I would like to get the element's name of "BookName". "ISBN" and "PublishDate " and only those names, not include " BookStoreInfo" and its child node's name
I tried several ways, but doesn't work, how can I do it?
Well, with XDocument
and LINQ-to-XML:
foreach(var name in doc.Root.DescendantNodes().OfType<XElement>() .Select(x => x.Name).Distinct()) { Console.WriteLine(name); }
There are lots of similar routes, though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With