Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Which XML module to use?

by BrowserUk (Patriarch)
on Jun 14, 2002 at 13:43 UTC ( [id://174510]=perlquestion: print w/replies, xml ) Need Help??

BrowserUk has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I read all the docs on the various flavours of XML::* (including the "Where to go from here" section) and am still undecided which I should use.

I also tried to follow the link in the following line (from my local html copy of the perldoc):

Don't forget to check out the Perl XML FAQ at: http://www.perlxml.com/faq/perl-xml-faq.html

but that leads to a music site?

My application will be reading an XML-likefile (no DTD or namespaces for now) and using the information to generate the HTML for a page - the XML will be used to supply the values for titles, tables, jpg/png's etc and the default values for fields in forms.

The size (and depth) of the structure should be fairly minimal to start with at least, but will no doubt get expanded over time.

Would those of you in the know, start with XML::Simple or XML:Lite or XML::Parser?

A short note indicating why you would go this route would be appreciated.


Sub-question: The XML::Simple contains the following statement:

XMLout() cannot produce well formed HTML unless you feed it with care - hash keys must conform to XML element naming rules and undefined values should be avoided.

which I do not understand. I see no other references to XMLout producing HTML? Is this a typo?

Replies are listed 'Best First'.
Re: Which XML module to use?
by mirod (Canon) on Jun 14, 2002 at 14:00 UTC

      Thanks for the references - persuing them now. (I have no idea what SAX is in this context yet - but hopefully I will soon:)

      With respect to:

      What is XML::Lite BTW, I have never hear of that module?

      Sorry! The module name should have been XML::Parser::Lite

      If anyone with editorial powers is reading this could they correct that for me as I appear not to be able to...by design I think!

        XML::Parser::Lite is designed to parse SOAP messages, which encompass only a subset of XML, so I would definitely not use it as a generic parser. XML::SAX::PurePerl is a generic XML parser written entirely in Perl.It is quite slow but this probably doesn't matter for you. And if you use XML::SAX you can always replace it later by a faster parser.

        BTW SAX is a standard api for processing XML in stream mode:it looks a bit like XML::Parser's basic api but is more recent and more powerful, especially when it comes to namespace processing (which you probably don't need right now). The most important features of SAX are that as it is standard you can swap parsers, go from a Perl one to a C one (like XML::libXML) or even use a parser that generates SAX calls from a non-XML source, such as Excel stylesheets (XML::SAXDriver::Excel) or CSV (XML::SAXDriver::CSV).

        IIRC XML::Parser::Lite is XML parser which supports subset of XML::Parser's API. Another difference is that XML::Parser::Lite is pure Perl module and XML::Parser is XS module which uses C library expat. Normally there is no reason to choose XML::Parser::Lite over XML::Parser since former is much faster and offers more capabilities. The only reason to use XML::Parser::Lite is that you have problems compiling XML::Parser on your platform.

        --
        Ilya Martynov (http://martynov.org/)

Re: Which XML module to use?
by Dog and Pony (Priest) on Jun 14, 2002 at 14:06 UTC
    I usually use XML::Simple, because it is just that - simple. Together with Data::Dumper to peek at the structure, you can accomplish the tasks really easily. However, as people has pointed out, XML::Simple builds a reference structure in-memory which might be big - whether this is a problem or not depends on your situation, of course.

    Next time I will do any more serious XML, I will most definetely look into XML::Twig - it seems to be very easy and simple to do things with too, with the added benefit of making it possible to "stream" your XML through it without the memory footprint. I've seen lots of great programmers here use that module, and without having actually used it myself - yet - I am very impressed.

    In the recent thread XML Search and Replace there are quite a few examples on different modules being used to manipulate XML.

    I don't think that is a typo. You can use XML::Simple to emit HTML, as long as you conform to XML rules, as XHTML does. It is just a warning that if you are trying to emit HTML, you can't/shouldn't do it HTML 4.0 (and down) style, but rather XHTML, which means, among other things, that all attributes must have a value. Just saying checked isn't enough in a checkbox, for instance, you must say checked="checked" or some such to be conformant. Which means, that an attribute, say as a hash key, is not a good idea to define as checked => '' (or undef), but should be checked => 'checked'. Hope that makes some sense. :)

    Update: See jeffa's response below, and don't take this as a recommendation to use XMLout() to generate HTML, only a clarification to what it meant. :)


    You have moved into a dark place.
    It is pitch black. You are likely to be eaten by a grue.
(jeffa) Re: Which XML module to use?
by jeffa (Bishop) on Jun 14, 2002 at 14:29 UTC
Re: Which XML module to use?
by cjf (Parson) on Jun 14, 2002 at 14:12 UTC

    I asked a similar question at Working with XML and received some good suggestions.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://174510]
Approved by coreolyn
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-04-19 10:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found