Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

How to implement XML languages

by gildir (Pilgrim)
on Jan 15, 2003 at 11:01 UTC ( [id://227114]=perlquestion: print w/replies, xml ) Need Help??

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

Fellow monks,

I have just a simple, yet difficult question:

What is the right way to implement XML languages?

I mean implementation of things like RDF, SAML, XKMS, XACML, etc. Should I subclass XML::Parser? Or write a standalone class that uses XML::Parser? What about schema chcecking? Is there any way that I can parse SAML assertion and at the same time check it against a schema? Please point my nose in the right direction.

Don't answer TIMTOWTDI, please. I'm aware that there is no single 'absolutly the right one' way to implement these languages. But I'm sure some of you already did things like that and there is much experience to share.

Thank you.

Replies are listed 'Best First'.
Re: How to implement XML languages
by ajt (Prior) on Jan 15, 2003 at 18:59 UTC

    gildir,

    Interesting question, hard to answer I fear.

    Traditionally people attacking an XML problem in Perl, build a single purpose module based on an XML Parser, for example XML::RSS or RPC::XML or SOAP::Lite. The module can deal with all the logic of converting XML into Perl data structures, and converting Perl data structures back to XML. A quick hunt round CPAN will show that there are lots of these modules there already.

    An alternative approach is to use Perl to handle the logistics, but let the data stay in XML. For example you can pretty much convert any kind of XML into XHTML or raw text quite easily with XSLT, you don't have to do it programmatically in Perl. As it happens Perl has some good SAX and XSLT technologies to use that are part of AxKit: XML::LibXML, XML::LibXSLT and XML::SAX. You just have to learn SAX or XSLT...

    Whatever the reason, unless you have a pressing reason I would not use XML::Parser to base a new module on, the c library it's based on (expat) is getting old, and it does not fully support all the current standards, and it does not support emerging standards. Instead I'd look at XML::LibXML which is very fast and very modern.

    Additional resources to look at:

    Here:

    CPAN:

    Elsewhere:

    Note: Bits of this post are shamlessly taken from earlier posts by me....


    --
    ajt
Re: How to implement XML languages
by dragonchild (Archbishop) on Jan 15, 2003 at 15:59 UTC
    Personally, I'd use XML::Parser to parse and use your module to implement the specification. I'm working on PDF::Template right now and it does just that. Makes a lot of sense to me, personally.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Re: How to implement XML languages
by vek (Prior) on Jan 15, 2003 at 19:13 UTC
    What about schema checking?

    While not answering your entire question I thought I'd point out Andy Wardley's XML::Schema

    -- vek --
Re: How to implement XML languages
by mirod (Canon) on Jan 15, 2003 at 19:33 UTC

    At this point I would not use XML::Parser as the base for a new tool, I would go the XML::LibXML way, unless libxml2 does nor run on the system you plan to use.

    If you need W3C schema support note that Andy Wardley just released []. I (and I am not alone in this, see this (long!) thread on xml-dev) don't like W3C schemas though, Relax NG (pronounced relaxing) seems like a much more sane way to go, see this message from James Clarke.

Re: How to implement XML languages
by grantm (Parson) on Jan 16, 2003 at 00:56 UTC
    Should I subclass XML::Parser?

    No, that kind of approach is deprecated these days.

    If you want access to the XML contents as an event stream (like XML::Parser's Handler interface) then the best option would be to use SAX. Your code would use XML::SAX::ParserFactory to get an object capable of parsing XML. This object might use XML::SAX::PurePerl, XML::LibXML::SAX, XML::SAX::Expat or something else depending on what was installed on the target machine. These parser modules are all written to the SAX API so you don't need to worry about which one you get.

    On the other hand, if you'd prefer to access the XML contents as a DOM tree then once again XML::Parser would not be the best answer. XML::Parser's Tree interface is not really an object model and certainly not DOM compliant. XML::DOM uses XML::Parser to provide a DOM level 1 API but a better bet would be either XML::LibXML or XML::GDOME which provide DOM level 2 APIs (XPath and namespace support being the key bits you want). Whether you'd subclass these modules or simply use them is up to you.

    You may find the Perl XML FAQ useful.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (7)
As of 2024-03-28 16:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found