I believe it's possible but couldn't figure out the syntax. Something like this:
xmlNode.SelectNodes("//*[count(child::*) <= 1]")
but this is not correct.
By adding square brackets with index. By using position () method in xpath.
In XPath, there are seven kinds of nodes: element, attribute, text, namespace, processing-instruction, comment, and document nodes. XML documents are treated as trees of nodes. The topmost element of the tree is called the root element.
Current node is the node that the XPath processor is looking at when it begins evaluation of a query. In other words, the current node is the first context node that the XPath processor uses when it starts to execute the query. During evaluation of a query, the current node does not change.
Use:
//node()[not(node())]
In case only element leaf nodes are wanted (and this needs clarification -- are elements that have non-element children considered leaf nodes?), then the following XPath expression selects them:
//*[not(*)]
Both expressions above are probably the shortest that select the desired nodes (either any-node or element -- leaf nodes).
Any elements with no element child
//*[not(child::*)]
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