# Introducing Xaggly, a C-based XML Parser for Ruby

**URL:** <https://www.ruby-forum.com/t/introducing-xaggly-a-c-based-xml-parser-for-ruby/80876>\
**Category:** Ruby\
**Created:** [December 31, 2006, 11:28pm UTC](https://www.ruby-forum.com/t/introducing-xaggly-a-c-based-xml-parser-for-ruby/80876 "2006-12-31T23:28:05Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![tnyplz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f17d59/32.png) [@tnyplz](https://www.ruby-forum.com/u/tnyplz)\
**Post date:** [December 31, 2006, 11:28pm UTC](https://www.ruby-forum.com/t/introducing-xaggly-a-c-based-xml-parser-for-ruby/80876/1 "2006-12-31T23:28:05Z")

</div>

I have written a C-based XML parser as a ruby plugin. I managed to  
benchmark it against REXML and Hpricot, and it appears to run quite  
speedily ([http://involution.com/images/xmlshootout.png](http://involution.com/images/xmlshootout.png)).

The source code is here:  
[http://involution.com/xaggly.tar.gz](http://involution.com/xaggly.tar.gz)

Unfortunately, my XPath support is very primitive right now. The  
package only supports fully qualified queries, and attribute searches  
aren’t working yet. So, you can search /html/body/\* to give you all  
of the tags open under body, but things like //p and //p[class=foo] do  
not work yet. Attributes are parsed and can be accessed from Ruby  
though.

I was trying to jigger this plugin to a gem, but it appears that mkmf  
doesn’t detect the presence of Flex and Bison files automatically. Is  
there a supported or standard for doing such a thing?

Regards,

Tony P.  
[http://involution.com](http://involution.com)

---

<div class="post-metadata">

**Author:** ![tnyplz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f17d59/32.png) [@tnyplz](https://www.ruby-forum.com/u/tnyplz)\
**Post date:** [January 1, 2007, 7:49pm UTC](https://www.ruby-forum.com/t/introducing-xaggly-a-c-based-xml-parser-for-ruby/80876/2 "2007-01-01T19:49:53Z")

</div>

Hi Tony,

On 12/31/06, Tony P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have written a C-based XML parser as a ruby plugin. I managed to  
> benchmark it against REXML and Hpricot, and it appears to run quite  
> speedily ([http://involution.com/images/xmlshootout.png](http://involution.com/images/xmlshootout.png)).

Sounds ambitious. Any reason you didn’t go with libxml? Have you  
tried benchmarking it against libxml?

---

<div class="post-metadata">

**Author:** ![tnyplz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f17d59/32.png) [@tnyplz](https://www.ruby-forum.com/u/tnyplz)\
**Post date:** [January 1, 2007, 7:55pm UTC](https://www.ruby-forum.com/t/introducing-xaggly-a-c-based-xml-parser-for-ruby/80876/3 "2007-01-01T19:55:55Z")

</div>

Tony P. wrote:

> I was trying to jigger this plugin to a gem, but it appears that mkmf  
> doesn’t detect the presence of Flex and Bison files automatically. Is  
> there a supported or standard for doing such a thing?

From my own limited experience, it is better to ship both the flex and  
bison sources files and the C files produced. My belief is that most of  
the time, ‘it will just work’. But I have limited experience with bison,  
flex and cross-platform stuff (apart from the fact that everytime I had  
a friend try one of my things on a different platform, I had to give him  
the C files because flex wasn’t understanding the same set of  
options…).

```
Vince
```

---

<div class="post-metadata">

**Author:** ![tnyplz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f17d59/32.png) [@tnyplz](https://www.ruby-forum.com/u/tnyplz)\
**Post date:** [January 1, 2007, 8:31pm UTC](https://www.ruby-forum.com/t/introducing-xaggly-a-c-based-xml-parser-for-ruby/80876/4 "2007-01-01T20:31:57Z")

</div>

Hmmm, I still wonder if it’s possible to coerce mkmf to handle .l and  
.y files in a general way so I can turn this into a gem.

Tony

---

<div class="post-metadata">

**Author:** ![tnyplz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f17d59/32.png) [@tnyplz](https://www.ruby-forum.com/u/tnyplz)\
**Post date:** [January 1, 2007, 10:48pm UTC](https://www.ruby-forum.com/t/introducing-xaggly-a-c-based-xml-parser-for-ruby/80876/5 "2007-01-01T22:48:10Z")

</div>

Tony P. wrote:

> Hmmm, I still wonder if it’s possible to coerce mkmf to handle .l and  
> .y files in a general way so I can turn this into a gem.

In my own experience, mkmf is not really flexible. I tried to make a  
more flexible version (see [mkmf2.rubyforge.org](http://mkmf2.rubyforge.org), quite outdated compared  
to cvs repository), but that isn’t really satisfying yet.

And, you’ll be bitten by options varying from one computer to  
another… Don’t expect also that everyone will have flex and bison  
installed.

---

<div class="post-metadata">

**Author:** ![tnyplz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f17d59/32.png) [@tnyplz](https://www.ruby-forum.com/u/tnyplz)\
**Post date:** [January 1, 2007, 8:29pm UTC](https://www.ruby-forum.com/t/introducing-xaggly-a-c-based-xml-parser-for-ruby/80876/6 "2007-01-01T20:29:56Z")

</div>

I tried using libxml, but a lot of RSS feeds aren’t really conformant.  
So, I had trouble reading in various feeds from different sites using  
libxml. While REXML and Hpricot worked, I found them to be fairly  
slow to parse large files. That was the impetus for me writing this  
library.

Tony  
[http://involution.com](http://involution.com)

---

<div class="post-metadata">

**Author:** ![tnyplz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f17d59/32.png) [@tnyplz](https://www.ruby-forum.com/u/tnyplz)\
**Post date:** [January 2, 2007, 1:16am UTC](https://www.ruby-forum.com/t/introducing-xaggly-a-c-based-xml-parser-for-ruby/80876/7 "2007-01-02T01:16:26Z")

</div>

Hi,

In message “Re: Introducing Xaggly, a C-based XML Parser for Ruby”  
on Tue, 2 Jan 2007 04:30:27 +0900, “Tony P.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
writes:

|Hmmm, I still wonder if it’s possible to coerce mkmf to handle .l and  
|.y files in a general way so I can turn this into a gem.

You can check ext/ripper/{extconf.rb,depend} for the trick. It’s in  
the Subversion 1.9.

```
						matz.

```

---

<div class="post-metadata">

**Author:** ![tnyplz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f17d59/32.png) [@tnyplz](https://www.ruby-forum.com/u/tnyplz)\
**Post date:** [January 2, 2007, 10:52pm UTC](https://www.ruby-forum.com/t/introducing-xaggly-a-c-based-xml-parser-for-ruby/80876/8 "2007-01-02T22:52:18Z")

</div>

Thank you.

Tony

---

<div class="post-metadata">

**Author:** ![tnyplz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f17d59/32.png) [@tnyplz](https://www.ruby-forum.com/u/tnyplz)\
**Post date:** [January 3, 2007, 7:40pm UTC](https://www.ruby-forum.com/t/introducing-xaggly-a-c-based-xml-parser-for-ruby/80876/9 "2007-01-03T19:40:01Z")

</div>

“Tony P.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> I tried using libxml, but a lot of RSS feeds aren’t really conformant.  
> So, I had trouble reading in various feeds from different sites using  
> libxml. While REXML and Hpricot worked, I found them to be fairly  
> slow to parse large files. That was the impetus for me writing this  
> library.

Can you show me a non-wellformed RSS feed in the wild? I often thought  
lots of them ought to exist, but I didn’t find one when I needed one…
