[Omaha.pm] XML::Twig demo

Jay Hannah jhannah at omnihotels.com
Wed Feb 11 16:46:39 PST 2009


Somebody asked me for a demo like this (irc.perl.org #perl-help) today.
 
j
 
 
 
$ 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>

 
<http://sf.net/projects/pastebot/>  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/omaha-pm/attachments/20090211/15855ddb/attachment.html>


More information about the Omaha-pm mailing list