Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

XML Compare and exact differences need to be listed out

by srikrishnan (Beadle)
on Sep 30, 2013 at 04:49 UTC ( [id://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.

Regards,

Srikrishnan

  • 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 (Priest) 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

    or

    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...
    • ..by my will, and by will alone.. I set my mind in motion

      Hi,

      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

      srikrishnan

        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...
        • ..by 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 (Archbishop) 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?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1056276]
Approved by Old_Gray_Bear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-04-20 02:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found