Reputation: 17
I got two XML's. XML 1 and xml 2. xml 2 is a subset of XML 1. I Need to get a final XML which has all the values of XML 1 but not XML 2.
Tried converting the XML values to comma separated strings and populate them in array and did string comparisons etc. But it did not work. Moreover, the size of the XML's can be very huge and is not a solution. I need this solved using XQUERY only.
xml1:
<root>
<f>a</f>
<f>b</f>
<f>c</f>
</root>
xml2:
<root>
<f>b</f>
<f>c</f>
</root>
Required XML: (XML 1 minus XML 2)
<root>
<f>a</f>
</root>
Kindly help with this request.
Upvotes: 0
Views: 93
Reputation: 167446
If the input structure is as simple and defined as shown you can simply select root/f[not(. = $xml2/root/f)]
to get the f
children which have no f
element in the other document with the same value:
declare variable $xml2 as document-node() external := document {
<root>
<f>b</f>
<f>c</f>
</root>
};
<root>
{
root/f[not(. = $xml2/root/f)]
}
</root>
https://xqueryfiddle.liberty-development.net/948Fn5m/1
Of course you can load the second document using doc('xml2.xml')
instead.
Upvotes: 1