Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XPath to Select Nodes Starting with a Certain Value

Tags:

xpath

Given the XML structure

<Doc>
   <Other />
   <Q1 />
   <Q2 />
</Doc>

How can I select only nodes that begin with a "Q", e.g. /Doc/Q1 and /Doc/Q2?

It seems like this can be done with starts-with, but I have only found examples that apply starts-with to the value of the node

like image 327
Eric J. Avatar asked Feb 18 '12 00:02

Eric J.


People also ask

Can you use XPath expression used to select the target node and its values?

XPath assertion uses XPath expression to select the target node and its values. It compares the result of an XPath expression to an expected value. XPath is an XML query language for selecting nodes from an XML. Step 1 − After clicking Add Assertion, select Assertion Category – Property Content.

What is the * indicates in XPath?

By adding '//*' in XPath you would be selecting all the element nodes from the entire document. In case of the Gmail Password fields, .//*[@id='Passwd'] would select all the element nodes descending from the current node for which @id-attribute-value is equal to 'Passwd'.


1 Answers

/Doc/*[starts-with(name(), 'Q')]

like image 178
penartur Avatar answered Sep 28 '22 04:09

penartur