Closed kndm closed 4 years ago
There seems to be a few diff-inserts that aren't warranted there, I'll try to get time to look into that.
@regebro could you tell me why I'm getting the xml diffs like this? I just changed the attribute on one node - https://pastebin.com/vBgzZYXj
I don't want to create an unnecessary issue
I have to go through the file and see how it maps and how nodes compare and things like that. It takes time, which is why I haven't done it yet. But I'll get to it, I promise. Node comparison can certainly be improved.
@kndm So, looking more closely, the big problem is that the files simply are so different that the matching algorithm doesn't find any match, as almost every level is full of differences, like percentages being integers in one file and decimals in one, and titles being different, etc. So it deletes almost all the content and inserts new content.
You can solve this with the -F parameter, that lowers the requirement for how similar a node needs to be to be counted as a match.
Hence, xmldiff file1.xml file2.xml -f xml -F 0.4
results in this output:
<result xmlns:diff="http://namespaces.shoobx.com/diff">
<iati-activity diff:delete-attr="default-currency;last-updated-datetime;{http://datastore.iatistandard.org/ns}version;{http://www.w3.org/XML/1998/namespace}lang">
<iati-identifier>CH-4-2008004812</iati-identifier>
<reporting-org ref="CH-4" type="10" diff:delete="">
<narrative>Swiss Agency for Development and Cooperation (SDC)</narrative>
</reporting-org>
<reporting-org diff:insert="" diff:rename="organisation" ref="CH-4" diff:add-attr="ref;secondary-reporter;type" secondary-reporter="0" type="10">
<narrative><diff:insert>Switzerland - </diff:insert>Swiss Agency for Development and Cooperation <diff:insert>(</diff:insert>SDC<diff:insert>)</diff:insert></narrative>
</reporting-org>
<title>
<narrative>OCHA Humanitarian Response Fund</narrative>
</title>
<description type="1">
<narrative>No description for this activity available at this point. Description indisponible pour cette activite.</narrative>
</description>
<participating-org ref="CH-4" type="10" diff:insert="" diff:rename="reporting-org" role="1" diff:add-attr="role">
<narrative>Swiss Agency for Development and Cooperation (SDC)</narrative>
</participating-org>
<participating-org ref="CH-4" role="1" type="10" diff:delete="">
<narrative>Swiss Agency for Development and Cooperation (SDC)</narrative>
</participating-org>
<participating-org ref="XM-DAC-41114" role="4" type="40">
<narrative>Programme des Nations Unies pour le developpement</narrative>
</participating-org>
<other-identifier ref="7F-06559.13.01" type="A1" diff:delete=""/>
<other-identifier diff:insert="" ref="7F-06559.13.01" diff:add-attr="ref;type" type="A1">
<owner-org diff:insert=""/>
</other-identifier>
<activity-status code="2"/>
<activity-date type="1" diff:insert="" diff:rename="other-identifier" diff:update-attr="type:A1" iso-date="2018-03-15" diff:add-attr="iso-date" diff:delete-attr="ref"/>
<activity-date iso-date="2018-03-15" type="2" diff:update-attr="type:1"/>
<activity-date iso-date="2018-12-31" type="3" diff:update-attr="iso-date:2018-03-15;type:2"/>
<activity-date iso-date="2018-12-31" type="4" diff:update-attr="type:3"/>
<activity-date iso-date="2018-12-31" type="4" diff:delete=""/>
<contact-info type="1">
<organisation diff:delete="">
<narrative>Swiss Agency for Development and Cooperation SDC</narrative>
</organisation>
<organisation diff:insert="" diff:rename="participating-org" diff:delete-attr="ref;role;type">
<narrative>Swiss Agency for Development and Cooperation <diff:delete>(</diff:delete>SDC<diff:delete>)</diff:delete></narrative>
</organisation>
<department>
<narrative>Statistics Unit</narrative>
</department>
<telephone>+41 58 464 92 35</telephone>
<email>stats.sdc@eda.admin.ch</email>
<website>http://www.sdc.admin.ch</website>
<mailing-address>
<narrative>Freiburgstrasse 130, 3003 Berne</narrative>
</mailing-address>
</contact-info>
<recipient-country code="SO">
<narrative diff:delete="">Somalie</narrative>
</recipient-country>
<sector vocabulary="1" code="72010" percentage="20.00" diff:update-attr="percentage:20"/>
<sector vocabulary="1" code="72050" percentage="30.00" diff:update-attr="percentage:30"/>
<sector vocabulary="1" code="72040" percentage="50.00" diff:update-attr="percentage:50"/>
<policy-marker code="6" significance="0" vocabulary="1" diff:add-attr="vocabulary">
<narrative>Aid Targeting the Objectives of the Framework Convention on Climate Change - Mitigation</narrative>
</policy-marker>
<policy-marker code="8" significance="0" vocabulary="1" diff:add-attr="vocabulary">
<narrative>Aid Targeting the Objectives of the Convention to Combat Desertification</narrative>
</policy-marker>
<policy-marker code="7" significance="0" vocabulary="1" diff:add-attr="vocabulary">
<narrative> Aid Targeting the Objectives of the Framework Convention on Climate Change - Adaptation </narrative>
</policy-marker>
<policy-marker code="2" significance="0" vocabulary="1" diff:add-attr="vocabulary">
<narrative>Aid to Environment</narrative>
</policy-marker>
<policy-marker code="5" significance="0" vocabulary="1" diff:add-attr="vocabulary">
<narrative>Aid Targeting the Objectives of the Convention on Biological Diversity</narrative>
</policy-marker>
<policy-marker code="9" significance="0" vocabulary="1" diff:add-attr="vocabulary">
<narrative> Reproductive, Maternal, Newborn and Child Health (RMNCH)</narrative>
</policy-marker>
<collaboration-type code="1"/>
<default-flow-type code="10"/>
<default-finance-type code="110"/>
<default-aid-type code="B03" vocabulary="1" diff:delete=""/>
<default-tied-status code="5"/>
<transaction ref="7F-06559.13.01">
<transaction-type code="2"/>
<transaction-date iso-date="2018-12-15" diff:insert="" diff:rename="activity-date" diff:update-attr="iso-date:2018-12-31" diff:delete-attr="type"/>
<transaction-date iso-date="2018-12-15" diff:delete=""/>
<value currency="CHF" value-date="2018-12-15">1000000<diff:insert>.00</diff:insert></value>
<description>
<narrative> Outgoing Commitment </narrative>
</description>
<sector code="72040" vocabulary="1" diff:insert="" diff:rename="default-aid-type" diff:update-attr="code:B03"/>
<sector diff:insert="" code="72050" diff:add-attr="code;vocabulary" vocabulary="1"/>
<sector diff:insert="" code="72010" diff:add-attr="code;vocabulary" vocabulary="1"/>
<recipient-country diff:insert="" code="SO" diff:add-attr="code"/>
<flow-type diff:insert="" code="10" diff:add-attr="code"/>
<finance-type diff:insert="" diff:rename="transaction-date" code="110" diff:add-attr="code" diff:delete-attr="iso-date"/>
<tied-status diff:insert="" code="5" diff:add-attr="code"/>
</transaction>
<transaction ref="7F-06559.13.01">
<transaction-type code="3"/>
<transaction-date iso-date="2018-12-15" diff:delete=""/>
<transaction-date iso-date="2018-12-15" diff:insert=""/>
<value currency="CHF" value-date="2018-12-15">1000000<diff:insert>.00</diff:insert></value>
<description>
<narrative> Disbursement</narrative>
</description>
<sector diff:insert="" code="72040" diff:add-attr="code;vocabulary" vocabulary="1"/>
<sector diff:insert="" code="72050" diff:add-attr="code;vocabulary" vocabulary="1"/>
<sector diff:insert="" code="72010" diff:add-attr="code;vocabulary" vocabulary="1"/>
<recipient-country diff:insert="" code="SO" diff:add-attr="code"/>
<flow-type diff:insert="" code="10" diff:add-attr="code"/>
<finance-type diff:insert="" code="110" diff:add-attr="code"/>
<tied-status diff:insert="" code="5" diff:add-attr="code"/>
</transaction>
<conditions attached="0"/>
</iati-activity>
</result>
@Utkarsh1308 I suggest you reopen your question as a new issue, with the example XML included. This is an artefact of how the comparison is done, and something that can be improved.
Closing as lacking feedback.
Unsure if this is a bug or intended, but it definitely seems like the former. Output presented is after running
xmldiff -f xml
with pretty print on, instead of generating the output needed to only change the left file, it is also including the whole data of the right file (and even adding diff markers to it)Input 1:
Input 2:
Output: