开发者

What are the Pros and Cons of a XML-Parser written completely in Perl

What are the Pros and Cons of an XML-Parser written completely in Perl to one only pr开发者_StackOverflowoviding an interface to a Parser like GNOME's LibXML?


Pro: More portable and easier to install (you don't need to compile pure Perl modules against C libraries, they'll run anywhere that the perl binary will run, you don't need to have a C compiler and the dev- libraries to link against if you want to build it on an arbitrary machine).

Con: Pure Perl (or any dynamic language for that matter) is comparatively slow when compared to heavily optimised C.


There are actually a few; XML::SAX::PurePerl and XML::Parser::Lite for example, but they are both slow and incomplete: the last time I checked XML::SAX::PurePerl still had some bugs, although you probably would not find them in Real Life, and XML::Parser::Lite is only supposed to parse the subset of XML used by SOAP.

In any case most systems come with either expat or libxml2, so in practice it doesn't seem to be such a big problem to rely on external libraries. Even on Windows expat is included both in Activestate Perl and in Strawberry Perl.

An XML parser is quite complex actually (you need to parse XML, but also DTDs, deal with entities...) so there is no need to re-invent this specific wheel, apart for entertainement^Wlearning purposes.


As mirod pointed out, incompleteness is sometime among Cons.

If you have to validate XML according to an XSD schema, things may get worse. There are modules that try to address this problem, like XML::Compile, or XML::Pastor, but you have to be tolerant on speed.

To give you some numbers, I'll talk about a Perl program I wrote to validate XML data that have to be schema compliant. My program uses XML::Parser, and MooseX::Types, and can take up to 10 seconds to validate a 5 MiB XML file.

On the other side,

xmllint --schema /path_to/schema.xsd data.xml

does the same task in a fraction of a second.

I got some speed ( and memory ) back using VTD-XML in the parsing phase, but still I have to validate data with Perl, because VTD-XML isn't ( still ) a validating parser.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜