# Compare 2 XML files with libxml-ruby

**URL:** <https://www.ruby-forum.com/t/compare-2-xml-files-with-libxml-ruby/190405>\
**Category:** Ruby\
**Created:** [June 19, 2010, 9:33am UTC](https://www.ruby-forum.com/t/compare-2-xml-files-with-libxml-ruby/190405 "2010-06-19T09:33:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nadinnne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bc8723/32.png) [@nadinnne](https://www.ruby-forum.com/u/nadinnne)\
**Post date:** [June 19, 2010, 9:33am UTC](https://www.ruby-forum.com/t/compare-2-xml-files-with-libxml-ruby/190405/1 "2010-06-19T09:33:04Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![nadinnne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bc8723/32.png) [@nadinnne](https://www.ruby-forum.com/u/nadinnne)\
**Post date:** [June 19, 2010, 5:29pm UTC](https://www.ruby-forum.com/t/compare-2-xml-files-with-libxml-ruby/190405/2 "2010-06-19T17:29:22Z")

</div>

On Jun 19, 3:33 am, Nadezda S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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/](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.
