Max Max - 2 months ago 15
Javascript Question

XPath find a child node of a node with partial strings

I am using xpath via npm and I am searching for an XPath 1.0 expression, such that the search after 'name' and 'run' should result in the following output.

Finding the first "parent node" using "//*[contains(name(), 'name')]" already works, but I don't know if it's possible to find a child by a part of its name (any number of levels below)?

input:

<root>
<NameX>
<getLenght>
<unit>m</unit>
</getLenght>
<getStatus>
<status>0</status>
</getStatus>
</NameX>
<Name2>
<getStatus>
<status>0</status>
</getStatus>
<running>
<bit>true</bit>
</running>
</Name2>
</root>


output:

<running>
<bit>true</bit>
</running>

Max Max
Answer Source

Andersson's answer is correct:

//*[contains(name(), 'name')]//*[contains(name(), 'run')]