RE: What's So Great about SAX? (ie. Future Indecisions)
by Grant McLean other posts by this author
Oct 7 2002 9:32PM messages near this date
view in the new Beta List Site
Re: What's So Great about SAX? (ie. Future Indecisions)
|
RE: What's So Great about SAX? (ie. Future Indecisions)
Hi Mr Iff
SAX has pluses and minuses and these will obviously depend
on your perspective. Comparing SAX to XML::Simple is a bit
of an apples and oranges comparison though.
If you're looking for something more powerful than XML::Simple,
then a DOM module like XML::XPath, XML::LibXML or (at a pinch
XML::DOM) is a better comparsion.
If you're looking for something to compare SAX to, then think
of the XML::Parser native API where you define event handlers.
SAX is a huge advance over the XML::Parser Handler API for a
number of reasons (including):
- pluggable - if your code is written to the SAX API you
can use any SAX parser without changing your code
- modular - you can write simple (single function) filter
classes and string them together for the desired result
- well supported - there are lots of existing SAX filters,
handlers, drivers and glue modules like XML::SAX::Base
and XML::SAX::Machines
- flexible - your data source does not even need to be an
XML document (eg: you can drive your SAX pipeline from
a database query
- namespace support (SAX2 only) which is consistent across
different parsers
However, as you have discovered SAX is not a panacea (does
anyone ever use the word 'panacea' without the 'is not a'
prefix?). If you're coming from an XML::Simple viewpoint,
then the first thing you notice about SAX is that you have
to write quite a lot of code to use it. It doesn't need to
be complex code and the API is not extensive, but you do
have to write rather a lot of it.
I'm not entirely clear on what you're trying to do with
namespaces. Do you want your hashref keys to be in Clarkian
notation eg: '{http://purl.org/dc/elements/1.1/}date' or
do you want to normalise the prefixes used eg: 'dc:date'?
XML::Simple version 1.08_01 will do the Clarkian notation
for you if you set nsexpand => 1 (as long as you're using
a SAX parser).
You could achieve the normalisation effect with a SAX filter
(does anyone have an XML::SAX::NSNormalise they'd like to
contribute to CPAN?). And if you use XML::Simple as the
handler on the end of the SAX pipeline you get the best of
both worlds.
Hope that helps
Grant
===============================================================
Grant McLean BearingPoint Inc - formerly The Web Limited
+64 4 495 8250 Level 6, 20 Customhouse Quay, Box 1195
gmclean@[...].biz Wellington, New Zealand
> -----Original Message-----
> From: Morbus Iff [mailto:morbus@[...].com]
> Sent: Tuesday, October 08, 2002 9:02 AM
> To: Perl-XML@[...].com
> Subject: What's So Great about SAX? (ie. Future Indecisions)
>
>
>
> I have a popular (nearly 40,000 downloads) piece of software. It's
> available on Mac (Classic and OS X), Windows (all), and most
> Linux systems
> I've tested it on. Currently, it's using XML::Simple to build various
> formats of XML into a hash/tree data structure. It's been
> doing that for
> the past two years now.
>
> I've gotten some other opinions on this, but
> roughly, I want to hear from the rest of the group:
>
> - is there any benefit from moving from
> XML::Simple to something like XML::SAX?
>
> Keep in mind:
>
> - expat is the only xml parser currently fully crossplatform
> for all my needs. it's also easily included into an
> .exe or application file (for Mac or Windows).
>
> - I'm using XML::Simple, and I only want things in a hashref.
>
> - I've been hacking up namespace recognition code to go
> with the hashref XML::Simple uses. This was the "last
> straw" that made me look into XML::SAX again.
>
> - I rarely use XML::Parser's API for anything crucial. The nearest
> is to stop XML::Simple from creating a hashref of the entire
> alphabet - I dump into XML::Parser to create a tree of only
> letter 'b', for example.
>
> - I'm a fan of readability. This attempt at SAX parsing for
> the format I'm interested in (RSS) is "ooky" and not
> code shui, in my head:
>
> http://aaronland.info/weblog/archive/4637
>
> A hearty thanks to Aaron for exploring that for me.
>
> - Common API portability isn't crucial to me, since
> XML::Simple figures all that crap out for me (thanks, Grant!).
>
> Thoughts?
>
>
> --
> Morbus Iff
_______________________________________________
Perl-XML mailing list
Perl-XML@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
|