XML::Genx

Dom2 on 2004-12-02T08:57:23

After seeing the article on Extending Ruby with C, I thought "I wonder how easy that would be in Perl?" The article is mostly about providing access to the Genx library. So, I spent a little while playing with it and came up XML::Genx. I don't know whether Perl needed another XML writing library; XML::SAX::Writer is pretty good. But Genx has some really useful features.

  • Doesn't require SAX. :-)
  • Will not output non-well-formed XML.
  • Always outputs UTF-8.
  • Ouputs canonical XML, which makes for much easier testing.

Anyway, it's been an interesting exercise. My C skills needed bringing out of storage, although I made few really daft mistakes. XS is still an "interesting" tool to work with. Coding at that level certainly makes you appreciate how high level Perl is.

On the whole though, the most useful surprise has been CPAN Testers. That's a really good way to find out that the world isn't just as FreeBSD faced as it looks like to me. Now all I need to do is figure out how to get a development environment working under windows.


Small World...

rooneg on 2004-12-02T15:56:45

You know, when I saw that on the CPAN recent modules list I'd wondered if it had been prompted by the article. Good to know people are reading my stuff ;-)

Re:Small World...

Dom2 on 2004-12-02T17:09:06

Your assertions about XS in there were quite correct. ;-)

The other thing I really admire about the ruby version is the block syntax. Of course, it's possible in Perl, just ugly. And no, I refuse to use a source filter.

But yes, thanks for the inspiration!

-Dom

Re:Small World...

rooneg on 2004-12-02T18:26:44

Another thing that wasn't mentioned in the article, but which is present in the latest version is a builder mode, so you can do stuff like this:

require 'genx/builder'

w = GenX::Writer.new(STDOUT)

w.builder do |b|
  b.foo do
    b.bar('blah')
    b.bar('zot')
  end
end

And get output like this:

<foo>
  <bar>blah</bar>
  <bar>zot</bar>
</foo>
This also caches elements and attributes so they don't get recreated each time through, and it adds pretty printing, so the output is easier to read. I need to go through and make it more configurable though, and write docs, and tests, and actually find a use for it so I don't feel like I'm wasting my time ;-)

Re:Small World...

Dom2 on 2004-12-02T19:43:04

I'm glad I'm not the only one implemented it "because it looks interesting". ;-)

That said, it's one of those things that I'm sure I'll find a use for before long, probably at work.

-Dom

Re:Small World...

Dom2 on 2004-12-02T21:57:31

Looking closer at that, I implemented something similiar before... That was interesting; I wanted to see how closures and SAX would go together.

-Dom