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.
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.
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).
not(*)
select leaf nodes/elements? –
Callous not(*)
means "does not have any element child" as "* selects all element children of the context node" as per the W3C XPath 1.0 recommendation: w3.org/TR/xpath/#path-abbrev (second bullet). This is a very short explanation, to go in depth, one needs a more or less full course in XPath. May I shamelessly recommend the second module of my Pluralsight training course on "XSLT 2.0 and 1.0 foundations"? The title of this course is "A Crash Course in XPath" and it is 70 minutes long: pluralsight.com/training/Courses/TableOfContents/… –
Angrist Any elements with no element child
//*[not(child::*)]
//*[not(*)]
? –
Overeager Why less or equal to 1 ?
xmlNode.SelectNodes("//*[count(child::*) = 0]")
Make tests etc at this site http://www.whitebeam.org/library/guide/TechNotes/xpathtestbed.rhtm
Pretty helpful ..
I'm adding this XSLT answer since it seems google's front matches lack such a solution:
After a long struggle with extracting CDATA as XML, eventually, this expression worked best for me:
<xsl:template match="*[not(child::*)]/text()">
© 2022 - 2024 — McMap. All rights reserved.