# Compare 2 XML files with libxml-ruby

**URL:** <https://rubytalk.org/t/compare-2-xml-files-with-libxml-ruby/58937>\
**Category:** ruby-talk\
**Created:** [19 June 2010 07:33 UTC](https://rubytalk.org/t/compare-2-xml-files-with-libxml-ruby/58937 "2010-06-19T07:33:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nadezda\_Sekret](https://avatars.discourse-cdn.com/v4/letter/n/d6d6ee/32.png) [@Nadezda\_Sekret](https://rubytalk.org/u/Nadezda_Sekret)\
**Post date:** [19 June 2010 07:33 UTC](https://rubytalk.org/t/compare-2-xml-files-with-libxml-ruby/58937/1 "2010-06-19T07:33:07Z")

</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!

Attachments:  
[http://www.ruby-forum.com/attachment/4812/diffscript.rb](http://www.ruby-forum.com/attachment/4812/diffscript.rb)

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![7rans](https://avatars.discourse-cdn.com/v4/letter/7/a8b319/32.png) [@7rans](https://rubytalk.org/u/7rans)\
**Post date:** [19 June 2010 15:28 UTC](https://rubytalk.org/t/compare-2-xml-files-with-libxml-ruby/58937/2 "2010-06-19T15:28:35Z")

</div>

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/%5C)) 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.

> **···**
>
> On Jun 19, 3:33 am, Nadezda Sekret \<nadja...@inbox.lv\> 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!
