XML, the Perl Way

Table of Content
Table of Content
Next
2. Introduction to XML

1. Introduction

XML::Twig is a Perl module used to process efficently XML documents

Twig offers a tree-oriented interface to a document while still allowing the processing of documents of any size. I think the current buzzword for it would be something like "push-pull" processing ;--)

When I was younger I wanted to grow up and write a tool that would allow people to process text the way they wanted, offering tons of feature, various ways to achieve the same result, not forcing them into any processing model but allowing them to use the one they felt the most comfortable with. Eventually I grew up and I realized a guy named Larry Wall had already written a language named Perl... Darn! So as I was quite involved in dealing with SGML, then XML documents, I decided to settle for the next best thing: writing a module that would allow people to process XML the way they wanted, offering them tons of feature, various ways... you get the point.

So I wrote XML::Twig. XML::Twig gives you a tree interface to XML documents... if you want. It also lets you dump parts of the tree, set callbacks during processing, both on tags and on subtrees, process only part of the tree... you name it. The only thing XML::Twig does not do is follow standards (except XML of course). Consider yourself warned!

This talk is aimed at programmers who want to process XML data with the XML::Twig module.

It will go from the basic functionnalities of the module to its most adanced use, offering numerous examples of code, from HTML conversion to database integration.

XML::Twig is a Perl module offering a push-pull processing model of XML data. In other words it lets you build a tree from an XML documents, while letting you output the results of your processing as its built. But more on that later...

This tutorial is available in XML (yapc_xmltwig.xml), converted to html using the talk2html script (which uses XML::Twig).

The latest version of the XML::Twig tutorial can be found on the XML::Twig page

1.0.1 Knowledge

Prior knowledge of Perl, especially its object-oriented aspects and regular expressions will probably help the reader. Familiarity with the DBI module wouldn't hurt either, but the examples are simple and detailed enough to offer a first introduction to data base processing using Perl.

Very little prior knowledge of XML is assumed, although a selection of related links is offered and would be of interest to the complete beginner.

1.1 Alternatives to XML::Twig

Of course other ways of processing XML documents exist, both using Perl and other languages, especially Java and Python.

You can find information on Perl modules on the Perl-XML FAQ, for a list of Python XML resources see Python and XML Processing and for a list of Java XML resources see Java (TM) Technology and XML.


Table of Content
Table of Content
Next
2. Introduction to XML