<HTML dir=ltr><HEAD>
<META http-equiv=Content-Type content="text/html; charset=unicode">
<META content="MSHTML 6.00.2900.3492" name=GENERATOR></HEAD>
<BODY>
<DIV><FONT face="Courier New" color=#000000 size=2>Somebody asked me for a demo like this (irc.perl.org #perl-help) today.</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<DIV><FONT face="Courier New" size=2>j</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<DIV><PRE>$ cat j.pl
#!/usr/bin/perl
use strict;
use XML::Twig;
my $twig = XML::Twig->new(
pretty_print => 'indented'
)->parse('<users/>')->root;
my @users = (
{ firstname => 'Jay',
lastname => 'Hannah'
},
{ firstname => 'Quentus',
lastname => 'Rex'
},
);
foreach (@users) {
my $elt = XML::Twig::Elt->new(
user => {
firstname => $_->{firstname},
lastname => $_->{lastname}
}
);
$elt->paste( last_child => $twig );
}
print $twig->sprint;
$ perl j.pl
<users>
<user firstname="Jay" lastname="Hannah"/>
<user firstname="Quentus" lastname="Rex"/>
</users>
</PRE>
<P></P>
<P></P>
<DIV align=right><FONT size=-1></FONT> </DIV>
<DIV align=right><FONT size=-1><A href="http://sf.net/projects/pastebot/"></A></FONT> </DIV></DIV></BODY></HTML>