Reputation: 1
I have XML db with only one collection (container) and I don't know the document names. How to get a entire XML document from db, which complies WHERE clause?
<root>
<node1>
<node2>
<node3>My Content</node2>
</node2>
</node1>
<root>
When I have queries
query 'collection("data1.dbxml")/root/node1/node2[node3 = "My Content"]/string()'
it returns a content from that node3
'My Content'
and
query 'collection("data1.dbxml")/root/ode1/node2/node3'
it returns 2 internal nodes with the content
<node2><node3>My Content</node3></node2>
But how to get whole document which complies this WHERE clause (sth like SELECT * FROM data2.dbxml WHERE node3='My Content'?
Upvotes: 0
Views: 705
Reputation: 1
another resolution ... after studying :)
query 'for $x in collection("data1.dbxml")
where $x/root/node1/node2/node3 = "My Content"
return $x'
or when we know the depth of node in XMLdoc and node's name
query 'for $x in collection("data1.dbxml")
where $x/*/*/*/node3 = "My Content"
return $x'
thanks W3Schools
Upvotes: 0
Reputation: 6218
Simply use a predicate as you did in the first example:
collection("data1.dbxml")/root[node1/node2/node3 = "My Content"]
You can think of the predicate in XQuery as the WHERE in SQL and the SELECT-part is everything before.
Upvotes: 1