Perl and XML

Author: John M. Gabriele | back to index

  • Perl and XML
  • ---

    My quick reference notes on using Perl with XML.

    Quick notes on XML

    Tiny XML refersher.

    Content of an XML file

    Structure and tags

    You specify the structure and tags of your XML files with either a DTD or a schema. DTD's came from SGML. Schema's are newer.

    The Perl Cookbook tells me that the W3C standard (http://www.w3.org/TR/xmlschema-0/) "XML Schema" is the most common schema language but also is complex and problematic.

    You usually use a schema or a DTD for validating an xml file against.

    Commonly-used Perl modules

    General use

    Use XML::Twig. Note, XML::Twig makes use of (actually, is a subclass of) the standard XML::Parser, which in turn talks to the expat C library. Don't directly use XML::Parser -- let wrappers like Twig talk to it for you.

    Also, for just writing simple XML files, XML::Simple can be quite useful.

    Validating XML files against a W3C Schema

    Use XML::Xerces. (XML::LibXML can do this, but it's currently undocumented.) See also XML::Validator::Schema.

    Validating XML files against a DTD

    Use XML::LibXML (which uses Gnome's libxml2). See also XML::Checker.

    Finding elements in a tree

    See XML::XPath support in XML::LibXML.

    Transforming XML files into some other format

    See XML::LibXSLT (built on Gnome's libxslt library).

    Links