RubyFlow The Ruby and Rails community linklog

×

The Ruby and Rails community linklog

Made a library? Written a blog post? Found a useful tutorial? Share it with the Ruby community here or just enjoy what everyone else has found!

Ox: Fast XML serialization

I recently released fast XML serializer called Ox also here. It is many time faster than Nokogiri and for Object serialization it is several times faster than Marshal. If there is enough interest I can provide some details as to what I did to make the underlying C code used in the extension as efficient as possible.

Comments

can we use this with active-resource xml data exchange, while rendering xml?

The parser will parse xml without the required xml prolog so I don’t think there should be a problem with parsing the xml. I know nothing about the rest of your environment though. The best way to find out might be a quick prototype.

Hey, would love to see what you did in the underlying c code and how it differs from what Nokogiri is doing. Great job!

@harisamin: Enjoy :-) https://github.com/ohler55/ox/blob/master/ext/ox/parse.c

Nokogiri leans on libxml whereas Ox seems to be playing its own game. (Correct me if I’m wrong..)

Ox does play it’s own game. No libxml. Just standard libs. Purpose build.

It looks interesting. How do you navigate through the xml? I can see if I parse the xml I can drill in using nodes like this xml.nodes[1].nodes[0] and xml.nodes[1].nodes[0].value - is there any easier way to walk through the xml? Can you add some examples to the readme? Thanks

The XML tree is basically that, each node has children in an Array and attributes in a Hash. You can iterate over the attributes or children (nodes) as you pointed out. I didn’t see an easier way to do that. Just introduced is a SAX like parser. That offers another way to walk the XML document. There are some examples on github. If you have something particular in mind let me know and I’ll provide an example.

It was easy to use Ox SAX parser - https://github.com/amolpujari/reading-huge-xml

Post a comment

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in