XML, the Perl Way

Processing XML with Perl Michel Rodriguez

XML::Writer

DBIx::XML_RDB

XML::Writer (cont'd)

Example

Generating a simple XML document with XML::Writer:

#!/bin/perl -w

use strict;
use XML::Writer;
use IO;

my $doc = new IO::File(">doc.xml");
my $writer = new XML::Writer(OUTPUT => $doc);

$writer->startTag("doc", class => "simple");              # print the tag with the attribute class
  $writer->dataElement( 'title', "Simple XML Document");  # print an element containing only text
  $writer->startTag( "section");
    $writer->dataElement( 'title', "Introduction",      
                           no => 1, type => "intro");
    $writer->startTag( "para");
      $writer->characters( "a text with");
      $writer->dataElement( 'bold', "bold");
      $writer->characters( " words.");
    $writer->endTag( "para");
  $writer->endTag();                                      # close section                    
  $writer->endTag( "doc");                                # close doc (or dies)
$writer->end();                                           # check that the document has only one element
$doc->close();


XML::Writer

DBIx::XML_RDB