0

In DB I have XML strings stored in a column. Below is my XML structure:

<?xml version="1.0"?>
-<ProductAttributes xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
-<Attribute Required="false" ID="2" Name="Color">
<Value ID="18">Light Pink</Value>
</Attribute>
-<Attribute Required="false" ID="1" Name="Size">
<Value ID="9">XL</Value>
</Attribute>
</ProductAttributes>

Another XML is:

<?xml version="1.0"?>
-<ProductAttributes xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
-<Attribute Required="false" ID="1" Name="Size">
<Value ID="1">S</Value>
</Attribute>
-<Attribute Required="false" ID="2" Name="Color">
<Value ID="4">Red</Value>
</Attribute>
-<Attribute Required="false" ID="3" Name="Weight">
<Value ID="6">10gr</Value>
</Attribute>
</ProductAttributes>

Notes

  1. There can be n number of xml strings and each xml string can have m number of tags

  2. Attribute nodes can in different order, for example in 1st attribute Id=1 can be first attribute and in 2nd attribute Id=1 can be last.

Requirement is not compare these n XML strings and find if any of strings has complete duplication of attributes (this comparison will consider values as order can be different).

Please guide and help me.

1

3 Answers 3

2

don't compare strings of XML. Use them as input to an XML parser that will turn them into XML trees, then search the trees for matching elements and compare their list of attributes.

Sign up to request clarification or add additional context in comments.

Comments

1

You could iterate all nodes of xml doc A and for each node, look up its xpath in xml doc B. If any paths are not found or the path is found but the value is different, the doc's are not 'the same'.

You'd then have to do the same for all nodes in B, checking the xpaths in A, to ensure there's nothing "in B but not in A"

Optimise by quitting as 'not equal' as soon as an xpath is not found or the values don't match.

Comments

1

You may want to try The XML Diff and Patch GUI Tool which you can download from here. I've used it before and it works ok.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.