Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

XML Compare and exact differences need to be listed out

by srikrishnan (Beadle)
on Sep 30, 2013 at 04:49 UTC ( #1056276=perlquestion: print w/replies, xml ) Need Help??
srikrishnan has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

I need one help. If anybody help me, it would be very helpful for me.

I want to compare 2 xml files. First XML is initially created one. Second XML is corrected one. Now I want to compare these two xml files and list out what are all the changes in between these two files. for example, in the corrected xml file, some spelling errors may corrected ('diferent' has been changed to 'different'). Now that whole type of list needs to be generated in a separate file.

I have checked both "File:Compare" and "XML:Compare" modules. First one, just give boolean report of whether both or same or not. Second one, list out the whole environment. For example, if a word in a paragraph is corrected means, it shows the whole paragraph as changed one. Instead of that I want only the particular words list.

Is there any module available for my purpose? Please give your suggestions to achieve the above said requirement.



  • Comment on XML Compare and exact differences need to be listed out

Replies are listed 'Best First'.
Re: XML Compare and exact differences need to be listed out
by wjw (Curate) on Sep 30, 2013 at 06:26 UTC
    There are a number of tools (many non-Perl) that will do this for you. However, to help you, it would help to know:

    • What environment are you in? Linux, Windows, OSX, other...?
    • Why are you only looking at Perl tools?
    For this kind of comparison I generally use TkDiff


    Meld or just plain old diff at the command line(this is on *nix of course).

    There are numerous tools for Windows as well. Winmerg being one of the free ones.

    If you are looking for exclusively programmatic solutions, then knowing more about your environment is almost mandatory.

    A quick google search for "diff tools written in perl" came back with Algorithm::Diff, which contrary to its name seems to do what you are describing."Algorithm::Diff - Compute `intelligent' differences between two files / lists"

    Hope something in there is useful...

    • ...the majority is always wrong, and always the last to know about it...
    • my will, and by will alone.. I set my mind in motion


      Thanks for your reply

      I am in Windows 7 and Activestate perl 5.10

      I am working in Arbortext Advanced print Publisher (3B2) software for Typesetting, this software supports perl, I want to include a perl script in this software for my requirement

      Thanks a lot


        Ok, that is a start. We know ActiveState and Win7.

        From your original post, your requirements are:

        • Output is to be a 3rd file containing the differences between original XML and corrected XML
        • Your changes may be as small as the spelling of a single word.
        What other differences would you want to capture?
        • Will a line by line compare work for you?
        • Do you expect larger changes, such as reordering of lines, replacement of lines/sections of the XML?
        • What do you expect the resultant file to look like? (line_number, orig_line, mod_line, change_txt...
        • I guess that leads to the question, what are you going to do with the output you generate? How will you use it?
        I see from some of your previous postings that you do know some Perl.

        You really do need to provide more info when you ask questions though.

        See How do I post a question effectively?.

        It will help others to help you more effectively. Best of luck ...

        • ...the majority is always wrong, and always the last to know about it...
        • my will, and by will alone.. I set my mind in motion
Re: XML Compare and exact differences need to be listed out
by ww (Bishop) on Sep 30, 2013 at 13:46 UTC
    Show us your code and how it fails. We're here to help you learn; not -- as you appear to be requesting (in your replies to helpful advice below) -- that we write the code for you. See On asking for help.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1056276]
Approved by Old_Gray_Bear
[Corion]: choroba: Yeah - I basically have the same for regenerating README and README.mkdown already, except that I do that in Makefile.PL, but I guess one or the other thing should somehow work ;)
[ambrus]: was this bug: https://rt.cpan. org/Public/Bug/ Display.html?id= 59814
[Corion]: ambrus: Oh - that one would be much harder to automate... The SYNOPSIS section should mostly be a runnable program IMO, but I write only small snippets in my documentation for single functions/methods, and creating the appropriate environment for ...
[Corion]: ... those in an automated fashion seems somewhat hard to me. Although it should do wonders for the test coverage ;)
[haukex]: Corion: I once wrote an automated thingy for that here
[haukex]: here's the code that uses it

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (11)
As of 2017-02-27 12:18 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (385 votes). Check out past polls.