# Ruby xml parser opinions?

**URL:** <https://www.ruby-forum.com/t/ruby-xml-parser-opinions/133807>\
**Category:** Ruby\
**Created:** [April 3, 2008, 9:00pm UTC](https://www.ruby-forum.com/t/ruby-xml-parser-opinions/133807 "2008-04-03T21:00:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ddancer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ecb155/32.png) [@ddancer](https://www.ruby-forum.com/u/ddancer)\
**Post date:** [April 3, 2008, 9:00pm UTC](https://www.ruby-forum.com/t/ruby-xml-parser-opinions/133807/1 "2008-04-03T21:00:56Z")

</div>

I’m revisiting an app that uses libxml for xml work. Wondering if  
anyone has opinions on what is the best available XML parser for Ruby?

REXML seems to get trashed at every opportunity. Hpricot is getting  
some good press, but is it better than libxml? Most posts I’ve seen  
when someone chooses hpricot over libxml is because they are running  
on Windows.

Found this post “[http://yomi.at/archives/19](http://yomi.at/archives/19)” which seems recent and  
clearly shows libxml as the parser of choice when speed is the primary  
consideration.

Any thoughts?

---

<div class="post-metadata">

**Author:** ![ddancer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ecb155/32.png) [@ddancer](https://www.ruby-forum.com/u/ddancer)\
**Post date:** [April 4, 2008, 12:16am UTC](https://www.ruby-forum.com/t/ruby-xml-parser-opinions/133807/2 "2008-04-04T00:16:26Z")

</div>

Andy K. wrote:

> I’m revisiting an app that uses libxml for xml work. Wondering if  
> anyone has opinions on what is the best available XML parser for Ruby?
> 
> REXML seems to get trashed at every opportunity. Hpricot is getting  
> some good press, but is it better than libxml? Most posts I’ve seen  
> when someone chooses hpricot over libxml is because they are running  
> on Windows.
> 
> Found this post “[http://yomi.at/archives/19](http://yomi.at/archives/19)” which seems recent and  
> clearly shows libxml as the parser of choice when speed is the primary  
> consideration.
> 
> Any thoughts?

Hpricot is awesome, but if I need to have anything that parses  
namespaces, I use REXML. I don’t like REXML at all, but it handles  
namespaces well enough. Hpricot is so easy to use you have ever used  
CSS that its hard not to recommend.

---

<div class="post-metadata">

**Author:** ![ddancer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ecb155/32.png) [@ddancer](https://www.ruby-forum.com/u/ddancer)\
**Post date:** [April 4, 2008, 2:46am UTC](https://www.ruby-forum.com/t/ruby-xml-parser-opinions/133807/3 "2008-04-04T02:46:39Z")

</div>

On Apr 3, 2008, at 1:00 PM, Andy K. wrote:

> consideration.
> 
> Any thoughts?

depends entirely on your use case

- skimming a small amount of data from nested nodes → hpricot

- parsing a hierarchy where attrs and relationship of parent ↔ child  
is important → rexml

a @ [http://codeforpeople.com/](http://codeforpeople.com/)

---

<div class="post-metadata">

**Author:** ![ddancer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ecb155/32.png) [@ddancer](https://www.ruby-forum.com/u/ddancer)\
**Post date:** [April 4, 2008, 11:40am UTC](https://www.ruby-forum.com/t/ruby-xml-parser-opinions/133807/4 "2008-04-04T11:40:43Z")

</div>

2008/4/3, Andy K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> I’m revisiting an app that uses libxml for xml work. Wondering if  
> anyone has opinions on what is the best available XML parser for Ruby?
> 
> REXML seems to get trashed at every opportunity.

It may seem so. But keep in mind that if something does not work as  
expected people will shout loudly - while all those that are satisfied  
are usually quietly enjoying it. Whenever I have to do XML in Ruby I  
use REXML. Granted, I don’t have large files to handle right now but  
if, I would try using REXML’s stream parser instead of doing anything  
else.

> Found this post “[http://yomi.at/archives/19](http://yomi.at/archives/19)” which seems recent and  
> clearly shows libxml as the parser of choice when speed is the primary  
> consideration.

Probably true, but with the stream based approach you can also get  
more out of REXML. I like the fact that it does not require a binary  
extension and is part of the standard install. Ultimate speed for me  
is not as important as availability and portability of my scripts.

YMMV

Kind regards

robert
