I'm pretty new to XSLT/Xquery and would like to compare two xml files ( data content and can ignore white spaces and comments) and print the changed nodes of the second xml. As per my knowledge( googled ) i believe it can be done using Xquery. My xml will look like below.
<ns:Batch xmlns:ns="http://www.sample.com/">
<ns:Product>
<ns:productId>AB02921</ns:productId>
<ns:type>Product</ns:type>
<ns:productDescription>
<ns0:string xmlns:ns0="http://www.sample.com/core" country="US" language="en">EVE BOOTCUT JEAN</ns0:string>
</ns:productDescription>
<ns:productLongDescription>
<ns0:string xmlns:ns0="http://www.sample.com/core" country="US" language="en">For perennial cool with an uber comfortable tw...</ns0:string>
</ns:productLongDescription>
<ns:posDetails>
<ns:isTemplate>false</ns:isTemplate>
</ns:posDetails>
<ns:isTemplate>false</ns:isTemplate>
<ns:lastUpdated>2011-09-07T16:52:50.573</ns:lastUpdated>
<ns:exportDetails>
<ns:isTemplate>false</ns:isTemplate>
</ns:exportDetails>
<ns:mmGroupId groupTypeId="mmGroup" groupHierarchyId="ABC" variantGroupTypeId="region" variantGroupId="All" variantGroupHierarchyId="All">JSBFO</ns:mmGroupId>
<ns:inventoryDetails>
<ns:isTemplate>false</ns:isTemplate>
</ns:inventoryDetails>
<ns:productDimensions>
<ns:isTemplate>false</ns:isTemplate>
</ns:productDimensions>
<ns:warrantyDetails>
<ns:isTemplate>false</ns:isTemplate>
</ns:warrantyDetails>
<ns:standardCostPrice>0.0</ns:standardCostPrice>
<ns:standardMargin>0.0</ns:standardMargin>
<ns:colourId colourRangeId="Default">6007</ns:colourId>
<ns:sizeId sizeRangeId="Default">14</ns:sizeId>
<ns:styleId>AB029</ns:styleId>
</ns:Product>
I need to compare against all these repeating nodes of can return the changed nodes within this node. Request all to help me with the same. Regards, Sri.
Comparing two XML documents is a challenging task, partly because people who ask for this as a rule don't have a good definition of the problem and actually don't know exactly what they are asking for.
This said, try this standard XPath 2.0 function:
deep-equal()
XML Comparison is not trivial. I tend to use XMLUnit http://xmlunit.sourceforge.net/ for this kind of problem
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With