Reputation: 541
I have an xml structure like this:
<node1>
<node2 name="">
</node2>
<node2 name="">
</node2>
<node2 name="">
</node2>
....
</node1>
How can i write an xquery to find if there is a node2 that has name=a
Please help, thank you!
I tried the following but neither seemed to work. What is wrong with these queries?
select tbl.query('node1/node2[@name="a"]')
from tbl
select tbl.query('node1/node2[@name=''a'']')
from tbl
Upvotes: 2
Views: 241
Reputation: 338376
You'd simply select /node1/node2[@name = 'a']
(or //node2[@name = 'a']
) with XPath.
If the select result is empty, there is no matching node.
Upvotes: 4