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

Hi, My requirement is to compare two xml files and generate an xml file with differences(xmldelta). But here the problem is the modules(XML::Diff) which I installed are taking lot of memory(even 2 GB RAM is not sufficient). I am thinking that those modules are using XML::Parser which in turn uses DOM Parser so that taking lot of memory. Is there any way in perl which will do that using SAX Parser? Please help in this regard. Thanks in advance. Regards, L.Srikanth Kumar
  • Comment on How can I compare two XML files with less memory

Replies are listed 'Best First'.
Re: How can I compare two XML files with less memory
by starX (Chaplain) on Jul 25, 2007 at 19:19 UTC
    You might want to give AnyData::Format::XML a look. From the introduction, it sounds like you should be able to use it to compare the contents of two XML files as if they were two databases, without having to slurp either file into memory. I imagine that you could then use database queries to find the differences between the two files and write those to another file, but then again, I've been doing a lot of database work recently, and you know what they say everything looks like to a man with a hammer. :)
Re: How can I compare two XML files with less memory
by CountZero (Bishop) on Jul 25, 2007 at 18:57 UTC
    There is another module that does something similar: XML::SemanticDiff but it also uses XML::Parser, so it is likely to give you the same memory problems.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re: How can I compare two XML files with less memory
by polettix (Vicar) on Jul 26, 2007 at 09:35 UTC
    XML::Twig was created by mirod with huge XML files in mind. Whether it suits your needs or not... only you can judge :)

    Flavio
    perl -ple'$_=reverse' <<<ti.xittelop@oivalf

    Don't fool yourself.
Re: How can I compare two XML files with less memory
by Jenda (Abbot) on Aug 04, 2007 at 18:41 UTC

    I don't think we can help much if you do not give us more details regarding the format of the XMLs, what kind of differences do you expect and how do you want to compare them.Maybe you could parse the file in chunks and compare the chunks, but if that's possible and how to do that ... that's a question.

    You'd probably need to use a pull parser, XML::LibXML::Reader or XML::TokeParser, to be able to parse the two files at once and decide from which you want the next piece.