Compare 2 XML files with libxml-ruby

Hello!

I wrote ruby script, which parse 2 XML files and compare them using
libxml-ruby. If difference is found - puts message about it.
But this script works long. I am new in ruby and don’t know how to
change it, maybe someone can help me to improve my script?
I am parsing large XML files. (~30M)
My script is in attachment.

Thank You!

On Jun 19, 3:33 am, Nadezda S. [email protected] wrote:

Hello!

I wrote ruby script, which parse 2 XML files and compare them using
libxml-ruby. If difference is found - puts message about it.
But this script works long. I am new in ruby and don’t know how to
change it, maybe someone can help me to improve my script?
I am parsing large XML files. (~30M)
My script is in attachment.

Thank You!

First of a couple of pointers.

  • Indent two spaces. That is the Ruby common practice and will make
    your code easier to read. (If don’t like such shallow indention then
    use 4, but please 8 is just too much).
  • Post large samples like this to snippets sites such as github’s gist
    (http://gist.github.com/) it will colorize the output nicely, again
    making it easier to read.
  • Add some comments to the code to explain what is going on. People
    not familiar with libxml-ruby might be able to help if they knew how
    XML::Reader worked.

Having said that, you might get better performance if you eliminate
where the two documents are the same, then what is left over will be
their differences. Just a thought.