Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

DiffXML to compare XML files gives confusing outputs

$
0
0
So I'm trying to use the XMLDiff Microsoft provides to find the difference between two XML files. The aim is to compare two XML files and find out the exact differences so I can make an Audit Trail out of them. The files may have difference structures (nodes added or removed). 

However, the XMLDiff seems to give me an unexpected output when it comes to nested repeating structures.

Example XML #1 (original):

<pd:AP xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:pd="http://www.ascentn.com/bpm/XMLSchema"><pd:processFields /><pd:formFields><pd:TextBox1>val 1</pd:TextBox1><pd:DropdownList1>Option 4</pd:DropdownList1><pd:TextBox2>val 2</pd:TextBox2><pd:CheckBox1>Option 2;Option 3;Option 4</pd:CheckBox1><pd:SubForm1_SubForm><pd:SubForm1><pd:TextBox3>val 3</pd:TextBox3><pd:DropdownList3>Option 3</pd:DropdownList3><pd:DropdownList2>Option 2</pd:DropdownList2></pd:SubForm1><pd:SubForm1><pd:TextBox3>val 4</pd:TextBox3><pd:DropdownList3>Option 5</pd:DropdownList3><pd:DropdownList2>Option 3</pd:DropdownList2></pd:SubForm1></pd:SubForm1_SubForm></pd:formFields></pd:AP>


Example XML #2 (modified):

    
<pd:AP xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:pd="http://www.ascentn.com/bpm/XMLSchema"><pd:processFields /><pd:formFields><pd:TextBox1>val 1.changed</pd:TextBox1><pd:DropdownList1>Option 4</pd:DropdownList1><pd:TextBox2>val 2</pd:TextBox2><pd:CheckBox1>Option 2;Option 3;Option 4</pd:CheckBox1><pd:SubForm1_SubForm><pd:SubForm1><pd:TextBox3>val 3.changed</pd:TextBox3><pd:DropdownList3>Option 3</pd:DropdownList3><pd:DropdownList2>Option 2</pd:DropdownList2></pd:SubForm1><pd:SubForm1><pd:TextBox3>val 4</pd:TextBox3><pd:DropdownList3>Option 5</pd:DropdownList3><pd:DropdownList2>Option 11</pd:DropdownList2></pd:SubForm1><pd:SubForm1><pd:TextBox3>val 6</pd:TextBox3><pd:DropdownList3>Option 3</pd:DropdownList3><pd:DropdownList2>Option 3</pd:DropdownList2></pd:SubForm1></pd:SubForm1_SubForm></pd:formFields></pd:AP>


The Diff XML File I get is :

    
<?xml version="1.0" encoding="utf-8"?><xd:xmldiff version="1.0" srcDocHash="12260906919056999448" options="IgnoreChildOrder IgnoreNamespaces IgnorePrefixes " fragments="no" xmlns:xd="http://schemas.microsoft.com/xmltools/2002/xmldiff"><xd:node match="1"><xd:node match="2"><xd:node match="5"><xd:add type="1" name="SubForm1" ns="http://www.ascentn.com/bpm/XMLSchema" prefix="pd"><xd:add><pd:DropdownList2 xmlns:pd="http://www.ascentn.com/bpm/XMLSchema">Option 11</pd:DropdownList2></xd:add><xd:add match="/1/2/5/2/1-2" opid="1" /></xd:add><xd:node match="1"><xd:node match="1"><xd:change match="1">val 3.changed</xd:change></xd:node></xd:node><xd:node match="2"><xd:add><pd:TextBox3 xmlns:pd="http://www.ascentn.com/bpm/XMLSchema">val 6</pd:TextBox3><pd:DropdownList3 xmlns:pd="http://www.ascentn.com/bpm/XMLSchema">Option 3</pd:DropdownList3></xd:add><xd:remove match="1-2" opid="1" /></xd:node></xd:node><xd:node match="1"><xd:change match="1">val 1.changed</xd:change></xd:node></xd:node></xd:node><xd:descriptor opid="1" type="move" /></xd:xmldiff>



This is quite strange because if you see the second node of pd:SubForm1, I have only changed the 3rd element inside it. Why does it pick it up as a node removed and added back again? Shouldn't it have flagged that as a change?

If I change the first two node in pd:SubForm1 then it picks it up as changed, but as soon as the 3rd (last node is changed) it flags it as a removal and addition (even if the first two are unchanged).

And I have IgnoreChildOrder flag set

    XmlDiff xmldiff = new XmlDiff(XmlDiffOptions.IgnoreChildOrder |
                                            XmlDiffOptions.IgnoreNamespaces |
                                            XmlDiffOptions.IgnorePrefixes);



Any idea how to bypass this or any thoughts on how to it in a better way?

Any help would be highly appreciated.

Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>