in reply to Re^2: diff output of XML::SemanticCompare
in thread diff output of XML::SemanticCompare

I thought that may be there is a way to convert it to xml tags, since I need to display a difference in readable format on screen.

Of course there is a way, but you don't specify HOW it should be converted

I'd like to know if there is another way to display difference between two xml files...

Not using XML::SemanticCompare :)

That is the format XML::SemanticCompare uses for comparison of likeness

Its practically xpath, and hey, it is human readable, even if WIDE and vague :) its not meant for producing patches

#!/usr/bin/perl -- use strict; use warnings; use XML::SemanticCompare; my $control = <<'__XML__'; <?xml version="1.0" encoding="UTF-8"?> <moby:MOBY xmlns:moby="http://www.biomoby.org/moby" xmlns:foobar="http +://www.biomoby.org/moby2"> <moby:mobyContent> <moby:mobyData moby:queryID="sip_1_"> <moby:Simple moby:articleName="allele"> <moby:Object moby:id="cho" moby:namespace="DragonDB_Allele"/> </moby:Simple> </moby:mobyData> </moby:mobyContent> </moby:MOBY> __XML__ my $test = <<'__XML__'; <?xml version="1.0" encoding="UTF-8"?> <moby:MOBY xmlns:moby="http://www.biomoby.org/moby" xmlns:foobar="http +://www.biomoby.org/moby2"> <moby:mobyContent> <moby:mobyData moby:queryID="sip_1_"> <moby:Simple moby:articleName="allele"> <moby:Object moby:id="cho" moby:namespace="DragonDB_Allele"/> </moby:Simple> <moby:Simple moby:articleName="allele2"> <moby:Object moby:id="CHI" moby:namespace="DragonDB_Allele">fo +o</moby:Object> </moby:Simple> </moby:mobyData> </moby:mobyContent> </moby:MOBY> __XML__ my $C = XML::SemanticCompare->new(); my $diffs_arrayref = $C->diff($control, $test) ; for ( my $ix = 0; $ix < $#$diffs_arrayref; $ix +=2 ){ my $a = $diffs_arrayref->[$ix]; my $b = $diffs_arrayref->[$ix+1]; print "Old: \n", fart($a),"\n", "New: \n", fart($b),"\n", "#" x 33, "\n"; } sub fart { local $_ = $_[0]; s{\'\]/}{']\n /}g; return $_; } __END__ Old: /MOBY[namespace-uri() = 'http://www.biomoby.org/moby'] /mobyContent[namespace-uri() = 'http://www.biomoby.org/moby'] /mobyData[namespace-uri() = 'http://www.biomoby.org/moby'] /Simple[namespace-uri() = 'http://www.biomoby.org/moby'] / New: /MOBY[namespace-uri() = 'http://www.biomoby.org/moby'] /mobyContent[namespace-uri() = 'http://www.biomoby.org/moby'] /mobyData[namespace-uri() = 'http://www.biomoby.org/moby'] /Simple[namespace-uri() = 'http://www.biomoby.org/moby'] /@[articleName='allele2' and namespace-uri() = 'http://www.biomoby +.org/moby'] ################################# Old: /MOBY[namespace-uri() = 'http://www.biomoby.org/moby'] /mobyContent[namespace-uri() = 'http://www.biomoby.org/moby'] /mobyData[namespace-uri() = 'http://www.biomoby.org/moby'] /Simple[namespace-uri() = 'http://www.biomoby.org/moby'] /Object[namespace-uri() = 'http://www.biomoby.org/moby'] / New: /MOBY[namespace-uri() = 'http://www.biomoby.org/moby'] /mobyContent[namespace-uri() = 'http://www.biomoby.org/moby'] /mobyData[namespace-uri() = 'http://www.biomoby.org/moby'] /Simple[namespace-uri() = 'http://www.biomoby.org/moby'] /Object[namespace-uri() = 'http://www.biomoby.org/moby'] /@[namespace='DragonDB_Allele' and namespace-uri() = 'http://www.b +iomoby.org/moby'] ################################# Old: /MOBY[namespace-uri() = 'http://www.biomoby.org/moby'] /mobyContent[namespace-uri() = 'http://www.biomoby.org/moby'] /mobyData[namespace-uri() = 'http://www.biomoby.org/moby'] /Simple[namespace-uri() = 'http://www.biomoby.org/moby'] /Object[namespace-uri() = 'http://www.biomoby.org/moby'] /@[id='CHI' and namespace-uri() = 'http://www.biomoby.org/moby'] New: /MOBY[namespace-uri() = 'http://www.biomoby.org/moby'] /mobyContent[namespace-uri() = 'http://www.biomoby.org/moby'] /mobyData[namespace-uri() = 'http://www.biomoby.org/moby'] /Simple[namespace-uri() = 'http://www.biomoby.org/moby'] /Object[namespace-uri() = 'http://www.biomoby.org/moby'] /text()=foo #################################

Take a close look at the source, its really not that complicated

Esp see XML::SemanticCompare::SAX sub start_element

Replies are listed 'Best First'.
Re^4: diff output of XML::SemanticCompare
by gdanenb (Acolyte) on Sep 15, 2011 at 12:24 UTC

    Sorry, when I said that I want to see output as xml tags,
    I meant something like this:

    xml1:

    <job> <job-detail> <name>Symbian deactivation process</name> <group>Symbian</group> <description>Deactivates all expired symbains</description> </job-detail> </job>

    xml2:
    <job> <job-detail> <name>Symbian deactivation process</name> <group>Symbian</group> <description>Deactivates all expired symbains</description> </job-detail> </job> <job> <job-detail> <name>Distribution Content</name> <group>Distribution Cycle Group</group> <description>Updating the distribution content with one message< +/description> </job-detail> </job>

    and the result will be displayed as xml:
    <job> <job-detail> <name>Distribution Content</name> <group>Distribution Cycle Group</group> <description>Updating the distribution content with one message< +/description> </job-detail> </job>

Re^4: diff output of XML::SemanticCompare
by Anonymous Monk on Sep 15, 2011 at 08:06 UTC

    I've now changed my mind about Old/New , ie the return from ->diff, it appears its ALL New, stuff that isn't in old

    I'd have to run most of the other examples from the test suite to figure out how REMOVED and CHANGED items are signified

    But frankly, I hate XML , you can do if you're interested :)