#!/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"); # tag + att $writer->dataElement( 'title', "Simple XML Document");# text elt $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(); # close doc $writer->end(); # check that the doc # has only one element $doc->close(); # fixed (was $output->close(); ) as suggested by the post below