0

There is a xml document with content below:

    <Bookshop>
        <Book id="isbn-001"/>
        <Pen id="num-001" />
    </Bookshop>

I want to search the child nodes through the special id value, and the child node type is uncertain.

If the child nodes with same name/type, we can do it:select child with given attribute

 XmlNodeList nodelist = doc.SelectNodes("parent/child/node[@attribute='True']");

But in above xml, the child nodes aren't same name/type, should I do a loop method? Is there any select nodes method I can use. Thanks

Bes Ley
  • 1,685
  • 1
  • 20
  • 39
  • I think this can help you https://social.msdn.microsoft.com/Forums/vstudio/en-US/2db9013e-3c60-477e-89ef-3f791144fc73/correct-way-to-get-child-node-values-from-xml?forum=csharpgeneral – Damini Suthar May 23 '22 at 01:44
  • 1
    You can use an XPath expression with the wildcard `*` to select the required elements: `".//*[@id='isbn-001']"` to recursively search the entire document, or `/Bookshop/*[@id='isbn-001']` if `` is the root node. See [What is the difference between .// and //* in XPath?](https://stackoverflow.com/q/35606708) and [How to use XPath with XElement or LINQ?](https://stackoverflow.com/q/3642829). – dbc May 23 '22 at 05:33

0 Answers0