DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Hans has posted 19 posts at DZone. View Full User Profile

Perl XML::Twig (very Simple Example)

03.29.2006
| 1586 views |
  • submit to reddit
        Using XML::Twig

use XML::Twig;

my $xml = '<?xml version="1.0" ?>
<page id="1">
  <content>
      This is <div class="red">some HTML text</div>
  </content>
</page>';

my $twig = XML::Twig->new(
  twig_handlers => {
    content => sub { $_->print; print "\n";  },
  },
);

$twig->parse($xml);
$twig->purge;