Thursday, March 29, 2012

Equality comparison of xml fields

I have a stored procedure that has an xml input parameter, and the routine will proceed only when the inputted xml is equal to the stored xml field. Is there some sort of equals comparison for this?

* The xml field is typed DOCUMENT.XML data type instances are incomparable. XML data type preserves the content information of the XML instances and may not be an exact copy of the user-supplied XML data. Comparison depends upons the application semantics.

I can suggest the following for your application:

1) Extract scalar values (using the value() method) from the XML parameter and compare with scalar values in the stored XML field

2) Convert the XML parameter to a string representation and compare with a string representation of the stored XML field

3) Add a column that stores a hashed value of the XML instances. Get the hash value of the XML parameter and make a comparison of the hashed values. For a hash match, use #1 or #2 to ensure that the match is indeed correct. There are well known hashing methods (SHA-1 for example) that can yield good hash matches.

Hope this helps.

Thank you.|||Thanks Shankar for the reply. What I would do is break down this xml chunk into smaller content and perform the above as you suggested.

No comments:

Post a Comment