Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: diff output of XML::SemanticCompare

by gdanenb (Acolyte)
on Sep 15, 2011 at 06:47 UTC ( #926079=note: print w/ replies, xml ) Need Help??


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

I've read XML::SemanticCompare POD before using it.
The output I get is like:

/quartz[namespace-uri() = 'http://www.opensymphony.com/quartz/JobSched +ulingData']/job[namespace-uri() = 'http://www.opensymphony.com/quartz +/JobSchedulingData']/job-detail[namespace-uri() = 'http://www.opensym +phony.com/quartz/JobSchedulingData']/name[namespace-uri() = 'http://w +ww.opensymphony.com/quartz/JobSchedulingData']/text()=Distribution Co +ntent /quartz[namespace-uri() = 'http://www.opensymphony.com/quartz/JobSched +ulingData']/job[namespace-uri() = 'http://www.opensymphony.com/quartz +/JobSchedulingData']/job-detail[namespace-uri() = 'http://www.opensym +phony.com/quartz/JobSchedulingData']/description[namespace-uri() = 'h +ttp://www.opensymphony.com/quartz/JobSchedulingData']/text()=Updating + the distribution content with one message /quartz[namespace-uri() = 'http://www.opensymphony.com/quartz/JobSched +ulingData']/job[namespace-uri() = 'http://www.opensymphony.com/quartz +/JobSchedulingData']/job-detail[namespace-uri() = 'http://www.opensym +phony.com/quartz/JobSchedulingData']/job-class[namespace-uri() = 'htt +p://www.opensymphony.com/quartz/JobSchedulingData']/text()=com.cellti +ck.tasks.distributor.CCtDistributionContentJob /quartz[namespace-uri() = 'http://www.opensymphony.com/quartz/JobSched +ulingData']/job[namespace-uri() = 'http://www.opensymphony.com/quartz +/JobSchedulingData']/trigger[namespace-uri() = 'http://www.opensympho +ny.com/quartz/JobSchedulingData']/simple[namespace-uri() = 'http://ww +w.opensymphony.com/quartz/JobSchedulingData']/name[namespace-uri() = +'http://www.opensymphony.com/quartz/JobSchedulingData']/text()=Distri +bution Content Trigger /quartz[namespace-uri() = 'http://www.opensymphony.com/quartz/JobSched +ulingData']/job[namespace-uri() = 'http://www.opensymphony.com/quartz +/JobSchedulingData']/trigger[namespace-uri() = 'http://www.opensympho +ny.com/quartz/JobSchedulingData']/simple[namespace-uri() = 'http://ww +w.opensymphony.com/quartz/JobSchedulingData']/description[namespace-u +ri() = 'http://www.opensymphony.com/quartz/JobSchedulingData']/text() +=Triggers the broadcast task
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.

Regarding XML::SemanticDiff , I was sure that it's behavior is well known according http://ekawas.blogspot.com/2008_11_23_archive.html
If I append new elements to the end of file, it's working great.
But if some element is removed from begging of xml it displays a mess...

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


Comment on Re^2: diff output of XML::SemanticCompare
Download Code
Re^3: diff output of XML::SemanticCompare
by Anonymous Monk on Sep 15, 2011 at 07:58 UTC

    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

      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 :)

      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>

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://926079]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2014-07-31 03:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (244 votes), past polls