Select nodes where an attribute contains some sub-text

D

Duncan

Can I use the contains() function within an xpath query to return a
node whose attribute contains some text?

Something like: selectNodes("//Dataset[@Pattern contains(@Pattern,
'xyz')]

so for the given xml doc

<root>
<Datasets>
<Dataset name="dataset1" Pattern="abc" AnotherAttribute="xyz"/>
<Dataset name="dataset2" Pattern="xyz" AnotherAttribute="xyz"/>
<Dataset name="dataset3" Pattern="vwxyz"/>
</Datasets>
</root>

The nodes dataset2 and dataset3 would be returned because their
'Pattern' attribute contains the text 'xyz'.

Many thanks,

Duncan.
 
M

Martin Honnen

Duncan said:
Can I use the contains() function within an xpath query to return a
node whose attribute contains some text?
Yes.


Something like: selectNodes("//Dataset[@Pattern contains(@Pattern,
'xyz')]

That is syntactically wrong. A possible XPath expression could be
/root/Datasets/Dataset[contains(@Pattern, 'xyz')]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top