2008年4月18日 星期五

Write XML Documents by using Perl

These are two useful web pages.

http://search.cpan.org/~josephw/XML-Writer-0.604/Writer.pm

http://www.xml.com/pub/a/2001/04/18/perlxmlqstart1.html

For simplely, you can refer the usage of XML::Writer.

Following are part of content in these web pages, you can look out for them directly.

========


use XML::Writer;
use IO::File;

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

$writer->startTag("greeting", "class" => "simple");
$writer->characters("Hello, world!");
$writer->endTag("greeting");
$writer->end();
$output->close();


========


use XML::Writer;
require "files/camelid_links.pl";

my %camelid_links = get_camelid_data();
my $writer = XML::Writer->new();

$writer->xmlDecl();
$writer->startTag('html');
$writer->startTag('body');

foreach my $item ( keys (%camelid_links) ) {
$writer->startTag('a', 'href' => $camelid_links{$item}->{url});
$writer->characters($camelid_links{$item}->{description});
$writer->endTag('a');
}

$writer->endTag('body');
$writer->endTag('html');
$writer->end();

沒有留言: