#!/usr/bin/perl
use strict;
use warnings FATAL => 'all';
use 5.010;
use XML::Twig;
sub get_xml_from_data {
my @lines = <DATA>;
my $xml = join "", @lines;
return $xml;
}
sub main {
my $xml = get_xml_from_data();
my $xt = XML::Twig->new();
$xt->parse($xml);
my $root= $xt->root;
# output 1
say $root->first_child('element')->sprint;
# It will print:
#
# <element>
# Some content with <b>some</b> <i><b>other</b></i> tags.
# </element>
# output 2
say $root->first_child('element')->text;
# It will print:
#
# Some content with some other tags.
# But I need the output:
#
# Some content with <b>some</b> <i><b>other</b></i> tags.
}
main();
__DATA__
<root>
<element>
Some content with <b>some</b> <i><b>other</b></i> tags.
</element>
</root>
質問する
118 次