[xquery-talk] How can I search specific value through XQuery

Kunal Chauhan mail4ck at gmail.com
Tue Mar 29 15:36:58 PST 2011


Hi,

I have a XML file and I am trying find a specific attribute value from it.
The Whole senario is like when I am trying to search any value from the
document it gives me a value but not exact which I want.

For eg. If I want to find ABC from document it gives me ABC as well as
ABC_A, ABCD etc. but I want only ABC.

So, How can I retrive exact result.

Here is one Example which I tried.

My XML file

<doc>
<result id="instance" href="abc">
<hi>val1</hi>
<new>val2</new>
</result>
<result id="instance1" href="abc">
<hi>val1</hi>
<new>val2</new>
</result>
<result id="instance1" href="abcds">
<hi>val1</hi>
<new>val2</new>
</result>
</doc>

XQuery

declare variable $docs2 external;
let $docs2 := doc("D:/try.xml")/doc
for $x in $docs2
where $x/result[@href = 'abc']
return $x

And Result is as under

<doc>
<result id="instance" href="abc">
<hi>val1</hi>
<new>val2</new>
</result>
<result id="instance1" href="abc">
<hi>val1</hi>
<new>val2</new>
</result>
<result id="instance1" href="abcds">
<hi>val1</hi>
<new>val2</new>
</result>
</doc>


Thanks & Regards,

-- 
*Kunal Chauhan*
mail4ck at gmail.com
[+918655517141]
[+919904983614]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://x-query.com/pipermail/talk/attachments/20110329/a4c35637/attachment.htm


More information about the talk mailing list