use strict;
use warnings;
use XML::Twig qw( );
my $xml = <<'__EOI__';
__EOI__
{
my $seen = '';
my $t = XML::Twig->new(
twig_handlers => {
'ele' => sub { $seen .= $_->att('id') },
},
);
$t->parsestring($xml);
print("$seen\n");
print($seen eq 'a' ? "Standard\n" : "Not standard\n");
print($seen eq 'a' || $seen eq 'abc' ? "Consistent\n" : "Not consistent\n");
}
print("\n");
{
my $seen_null = '';
my $seen_foo = '';
my $t = XML::Twig->new(
map_xmlns => {
'uri:foo' => 'f',
},
twig_handlers => {
'ele' => sub { $seen_null .= $_->att('id') || $_->att('f:id') },
'f:ele' => sub { $seen_foo .= $_->att('id') || $_->att('f:id') },
},
);
$t->parsestring($xml);
print("$seen_null:$seen_foo\n");
print($seen_null eq 'a' ? "Standard\n" : "Not standard\n");
print($seen_null eq 'a' || $seen_null eq 'abc' ? "Consistent\n" : "Not consistent\n");
print($seen_foo eq 'bc' ? "NS working\n" : "NS broken\n");
}
####
ab
Not standard
Not consistent
a:bc
Standard
Consistent
NS working