We’re trying to filter a set of XML based on a value we provide.
We have the following XML in an XML field with our database, and if passing through the number “5052095050830”, we need to find this specific node in the XML. The number we provide may exist any number of times.
Can any body provide some example SQL to assist?
Thanks
<Attributes>
<ProductVariantAttribute ID="4387">
<ProductVariantAttributeValue>
<Value>5052095050830</Value>
</ProductVariantAttributeValue>
</ProductVariantAttribute>
<ProductVariantAttribute ID="9999">
<ProductVariantAttributeValue>
<Value>5052095050830</Value>
</ProductVariantAttributeValue>
</ProductVariantAttribute>
<ProductVariantAttribute ID="4388">
<ProductVariantAttributeValue>
<Value>104401330A</Value>
</ProductVariantAttributeValue>
</ProductVariantAttribute>
<ProductVariantAttribute ID="4389">
<ProductVariantAttributeValue>
<Value>6905</Value>
</ProductVariantAttributeValue>
</ProductVariantAttribute>
<ProductVariantAttribute ID="4390">
<ProductVariantAttributeValue>
<Value>6906</Value>
</ProductVariantAttributeValue>
</ProductVariantAttribute>
<ProductVariantAttribute ID="4391">
<ProductVariantAttributeValue>
<Value>Monday, October 27, 2008</Value>
</ProductVariantAttributeValue>
</ProductVariantAttribute>
</Attributes>
You can use the
.exist()method – something like this:This checks against that particular value you’ve supplied. The more precisely you can define the XPath where that value is expected to be found, the better for your performance.
is pretty bad – it looks into every single
<Value>node anywhere in the XML to find that value.Something like this:
would be much more focused and thus much better for performance – but it would only those those particular nodes defined by that very XPath statement