goldberg1 has asked for the wisdom of the Perl Monks concerning the following question:

I can't seem to get XML::Diff to work properly. As it walks up the tree, it seems to want to walk up *past* the root node of my document, then fails when the root node doesn't have a parent node. Has anyone else had this problem? Anyone have any experience working with XML::SemanticDiff instead? The documentation makes it seem a bit abstract. Any other experiences or hints for how to diff two XML files using Perl?

Replies are listed 'Best First'.
Re: XML diff
by moritz (Cardinal) on Jan 07, 2009 at 20:29 UTC
    Any other experiences or hints for how to diff two XML files using Perl?

    You've got some replies to this one on the CB, which you seemed to have ignored.

    The simplest possible way is to pretty-print both XML files in the same way, and use a regular text-diff tool (like diff -u on Unix).

    You might get better answers if you tell us what you need the diff for.

Re: XML diff
by runrig (Abbot) on Jan 07, 2009 at 21:53 UTC

    I haven't experienced the problem you describe with XML::Diff. The problem I have experienced is that the output is overly verbose. E.g., if you just change a few attributes, then the output is straight forward. But if you insert or delete a node, then you get a lot of node "updates" and "moves" along with the inserts or deletes (i.e. the changes are not optimal/minimal). But from what I've seen, you do get an accurate "patch" that will change the old file into the new file (which is what it says it does).

    XML::SemanticDiff does what it says, and seems to give a simpler set of changes for simple inserts and deletes of nodes. It's not meant to generate a patch like XML::Diff does, though you might be able to make one with a custom handler. There's an example of how to use the module in the docs. However, the pod for the docs appears to be broken right now (for me on 5.10 and on CPAN), so you may have to look in the source code for the docs. If you, e.g., delete an element with attributes, and you want a full description of the element and the attributes, you'll have to use the custom diff handler interface to get at those attributes. The basic default handler does work as advertised in the docs though.

      the pod for the docs appears to be broken right now (for me on 5.10 and on CPAN)
      The XML::SemanticDiff module maintainer just released version 1.0000 to CPAN in response to a patch I submitted last night for a POD error in version 0.99. Now, the following will correctly show the POD contents:
      perldoc XML::SemanticDiff
Re: XML diff
by zentara (Cardinal) on Jan 07, 2009 at 20:42 UTC
    There is quite a bit of discussion and usage discussion if you search google for "XML::SemanticDiff"

    I'm not really a human, but I play one on earth Remember How Lucky You Are
Re: XML diff
by goldberg1 (Initiate) on Jan 08, 2009 at 19:16 UTC
    Dear Monks, Thanks for all the responses, and sorry I missed the response in the chatterbox. I'm new to this forum (& how to use the chatterbox). While google searching down some of your suggestions, I came across this page: http://xmltwig.com/article/ways_to_rome/ways_to_rome.html which I thought some might find helpful. Thanks again!