mickthompson
mickthompson

Reputation: 5512

XPath - is it possible to query the node content?

I've this xml

<root>
    <node1>
        <node2>xxx</node2>
    </node1>
    ...
    <node1>
        <node2>yyy ABC yyy</node2>
    </node1>
    ...
    <node1>
        <node2>zzz</node2>
    </node1>
</root>

I want to get node1 that has a node2 containing the text ABC.
Is it possible to achieve this using XPath?

Upvotes: 1

Views: 182

Answers (3)

awshepard
awshepard

Reputation: 2737

I tried using this XPath Tester here: http://www.yetanotherchris.me/home/2010/6/7/online-xpath-tester.html. Does this work for you?

//node1/node2[contains(.,"ABC")]

Upvotes: 0

Marcelo Cantos
Marcelo Cantos

Reputation: 185972

//node1[node2[contains(text(),"ABC")]]

Upvotes: 1

Jon W
Jon W

Reputation: 15816

I'm pretty sure this will do the trick:

node1[node2[contains(text(),"ABC")]]

EDIT: Tested, seems to work.

Upvotes: 5

Related Questions