XML-Twig-3.52/ 0000755 0001750 0001750 00000000000 13015347632 013261 5 ustar mrodrigu mrodrigu XML-Twig-3.52/t/ 0000755 0001750 0001750 00000000000 13015347632 013524 5 ustar mrodrigu mrodrigu XML-Twig-3.52/t/xmlxpath_08name.t 0000755 0001750 0001750 00000001052 12732215763 016733 0 ustar mrodrigu mrodrigu #!/usr/bin/perl -w
use strict;
use FindBin qw($Bin); BEGIN { unshift @INC, $Bin; } use xmlxpath_tools;
use Test;
plan( tests => 5);
use XML::Twig::XPath;
ok(1);
my $t= XML::Twig::XPath->new->parse( \*DATA);
ok( $t);
my @nodes;
@nodes = $t->findnodes( '//*[name() = "BBB"]');
ok(@nodes, 5);
@nodes = $t->findnodes( '//*[starts-with(name(), "B")]');
ok(@nodes, 7);
@nodes = $t->findnodes( '//*[contains(name(), "C")]');
ok(@nodes, 3);
exit 0;
__DATA__
XML-Twig-3.52/t/xmlxpath_additional.t 0000755 0001750 0001750 00000014173 12732215763 017763 0 ustar mrodrigu mrodrigu #!/usr/bin/perl -w
use strict;
use strict;
use File::Spec;
use lib File::Spec->catdir(File::Spec->curdir,"t");
use tools;
use FindBin qw($Bin); BEGIN { unshift @INC, $Bin; } use xmlxpath_tools;
BEGIN
{ if( eval( 'require XML::Twig::XPath'))
{ import XML::Twig::XPath; }
elsif( $@ =~ m{^cannot use XML::XPath or XML::XPathEngine})
{ print "1..1\nok 1\n"; warn no_xpath_engine();
exit;
}
else
{ die $@; }
}
print "1..75\n";
use XML::Twig::XPath;
ok(1, "loading");
{
my $t= XML::Twig::XPath->new->parse( '5');
is( $t->to_number->as_string, 5, "to_number");
}
{
my $t= XML::Twig::XPath->new->parse( '5
');
is( $t->first_elt( 'p')->to_number->as_string, 5, "element to_number");
is( $t->getValue, 5, '$t->getValue');
}
{
my $t= XML::Twig::XPath->new->parse( 'foo
');
is( $t->first_elt( 'p')->to_number->as_string, "NaN", "to_number (NaN)");
}
{
my $t= XML::Twig::XPath->new->parse( 'p1
toto:p2
e1:e2
e3:e4
');
is( $t->findnodes_as_string( '//p'), '
p1
:p2
', "findnodes_as_string");
is( $t->root->findnodes_as_string( '//p'), 'p1
:p2
', "findnodes_as_string");
is( $t->root->findnodes_as_string( 'p'), 'p1
:p2
', "findnodes_as_string (from root)");
if( defined( $XML::XPathEngine::VERSION) ||
( $XML::XPath::VERSION && (($XML::XPath::VERSION eq '1.13.1') || $XML::XPath::VERSION >= 1.13) )
)
{ ok( $t->root->exists( '//p'), "exists //p (on root)");
ok( $t->exists( '//p'), "exists //p (on root)");
}
else
{ skip( 2, "your version of XML::XPath has a bug in the 'exists' method, you cannot use it with XML::Twig::XPath"); }
my $p= $t->first_elt( 'p');
ok( $p->matches( 'p'), "\$p->matches( 'p')");
ok( $t->matches( '//p', $p), "\$p->matches( 'p') (from the twig)");
my $p2_set= $t->root->find( 'p[text()= ":p2"]');
is( $p2_set->size, 1, "find 1 node");
is( $p2_set->to_literal, ':p2', 'p2 text');
my $s_set= $t->find( '//s[e/text()= ":e2"]');
is( $s_set->size, 1, "find 1 s node (nodeset)");
my @s= $s_set->get_nodelist;
is( scalar @s, 1, "find 1 s node nodelist");
my $s= shift @s;
is( $s->getValue, 'e1:e2', 's text');
}
{
my $t= XML::Twig::XPath->new( pi => 'process', comments => 'process')
->parse( 'text
foobar
');
nok( $t->isElementNode, '$t isElementNode');
nok( $t->isAttributeNode, '$t isAttributeNode');
nok( $t->isTextNode, '$t isTextNode');
nok( $t->isProcessingInstructionNode, '$t isProcessingInstructionNode');
nok( $t->isPINode, '$t isPINode');
nok( $t->isCommentNode, '$t isCommentNode');
nok( $t->isNamespaceNode, '$t isNamespaceNode');
ok( $t->getAttributes, '$t->getAttributes');
my $root= $t->root;
ok( $root->isElementNode, '$root isElementNode');
nok( $root->isAttributeNode, '$root isAttributeNode');
nok( $root->isTextNode, '$root isTextNode');
nok( $root->isProcessingInstructionNode, '$root isProcessingInstructionNode');
nok( $root->isPINode, '$root isPINode');
nok( $root->isCommentNode, '$root isCommentNode');
nok( $root->isNamespaceNode, '$root isNamespaceNode');
my $p= $t->first_elt( 'p');
ok( $p->isElementNode, '$p isElementNode');
nok( $p->isAttributeNode, '$p isAttributeNode');
nok( $p->isTextNode, '$p isTextNode');
nok( $p->isProcessingInstructionNode, '$p isProcessingInstructionNode');
nok( $p->isPINode, '$p isPINode');
nok( $p->isCommentNode, '$p isCommentNode');
nok( $p->isNamespaceNode, '$p isNamespaceNode');
my @att= $p->getAttributes;
my $att= shift @att;
is( $att->getName, 'att', '$att->getName');
is( $att->getValue, 'foo', '$att->getValue');
is( $att->toString, 'att="foo"', '$p attribute');
nok( $att->isElementNode, '$att isElementNode');
ok( $att->isAttributeNode, '$att isAttributeNode');
nok( $att->isTextNode, '$att isTextNode');
nok( $att->isProcessingInstructionNode, '$att isProcessingInstructionNode');
nok( $att->isPINode, '$att isPINode');
nok( $att->isCommentNode, '$att isCommentNode');
nok( $att->isNamespaceNode, '$att isNamespaceNode');
my $comment=$t->first_elt( '#COMMENT');
nok( $comment->isElementNode, '$comment isElementNode');
nok( $comment->isAttributeNode, '$comment isAttributeNode');
nok( $comment->isTextNode, '$comment isTextNode');
nok( $comment->isProcessingInstructionNode, '$comment isProcessingInstructionNode');
nok( $comment->isPINode, '$comment isPINode');
ok( $comment->isCommentNode, '$comment isCommentNode');
nok( $comment->isNamespaceNode, '$comment isNamespaceNode');
my $pi=$t->first_elt( '#PI');
nok( $pi->isElementNode, '$pi isElementNode');
nok( $pi->isAttributeNode, '$pi isAttributeNode');
nok( $pi->isTextNode, '$pi isTextNode');
ok( $pi->isProcessingInstructionNode, '$pi isProcessingInstructionNode');
ok( $pi->isPINode, '$pi isPINode');
nok( $pi->isCommentNode, '$pi isCommentNode');
nok( $pi->isNamespaceNode, '$pi isNamespaceNode');
is( $t->findvalue( '//foo:bar'), 'foobar', '//foo:bar');
is( $t->findvalue( '//*[@foo:att]'), 'foobar', '//*[@foo:att');
is( $t->findvalue( '//*[@foo:att=1]'), 'foobar', '//*[@foo:att=1]');
is( $t->findvalue( '//*[@foo:att=2]'), '', '//*[@foo:att=2]');
my $twig= ($root->findnodes( '..'))[0];
ok( UNIVERSAL::isa( $twig, 'XML::Twig'), 'findnodes returning the document node (' . ref( $twig) . ')');
my $back_to_root= ($root->findnodes( '../*'))[0];
is( $back_to_root->gi, 'doc' , 'findnodes returning the root through the document node');
}
# test namespace methods
{ my $ns= XML::Twig::XPath::Namespace->new( foo => "uri");
ok( $ns->isNamespaceNode, '$ns isNamespaceNode');
is( $ns->getPrefix, 'foo', 'getPrefix');
is( $ns->getExpanded, 'uri', 'getExpanded');
is( $ns->getValue, 'uri', 'getValue');
is( $ns->getData, 'uri', 'getData');
}
# check that set_text works also with XML::Twig::XPath
{ my $elt= XML::Twig::XPath::Elt->new( p => "foo");
$elt->set_text( "bar");
ok( 1, "set_text using XML::Twig::XPath");
}
exit 0;
XML-Twig-3.52/t/xmlxpath_04pos.t 0000755 0001750 0001750 00000000633 12732215763 016614 0 ustar mrodrigu mrodrigu use FindBin qw($Bin); BEGIN { unshift @INC, $Bin; } use xmlxpath_tools;
use Test;
plan( tests => 4);
use XML::Twig::XPath;
ok(1);
my $t= XML::Twig::XPath->new->parse( \*DATA);
ok( $t);
my $first = $t->findvalue( '/AAA/BBB[1]/@id');
ok($first, "first");
my $last = $t->findvalue( '/AAA/BBB[last()]/@id');
ok($last, "last");
exit 0;
__DATA__
XML-Twig-3.52/t/test_new_features_3_16.t 0000755 0001750 0001750 00000015765 12732215763 020214 0 ustar mrodrigu mrodrigu #!/usr/bin/perl -w
use strict;
use File::Spec;
use lib File::Spec->catdir(File::Spec->curdir,"t");
use tools;
use XML::Twig;
my $TMAX=85;
my $DEBUG=0;
print "1..$TMAX\n";
# state information are now attached to each twig
# default/fixed attribute values are now filled when the "load_DTD" option is used
my $dtd_file= 'test_default_att.dtd';
my $dtd=<<'DTD';
DTD
my $doc = q{};
my $filled_doc = q{}
.q{}
.q{}
.q{}
.q{}
.q{};
{
open( FHDTD, ">$dtd_file") or die "cannot open dtd file '$dtd': $!";
print FHDTD $dtd;
close FHDTD;
my $doc_with_external_dtd= qq{$doc};
my $result= XML::Twig->new( error_context => 1, load_DTD => 1)
->parse( $doc_with_external_dtd)
->root->sprint;
is( $result => $filled_doc, 'filling attribute default values with EXTERNAL DTD');
unlink $dtd_file;
}
{
my $doc_with_internal_dtd= qq{$doc};
my $result= XML::Twig->new( error_context => 1, load_DTD => 1)
->parse( $doc_with_internal_dtd)
->root->sprint;
is( $result => $filled_doc, 'filling attribute default values with INTERNAL DTD');
}
# test the first_descendant method
{
my $t= XML::Twig->new->parse( '');
is( $t->root->first_child->first_descendant( 'a')->tag, 'a', 'first_descendant succeeds');
nok( $t->root->first_child->first_descendant( 'b'), 'first_descendant fails (match outside of the subtree)');
}
# test the index option and method
{ my $doc=q{t1t2};
my $t= XML::Twig->new( index => [ 't', 'none' ])->parse( $doc);
is( $t->index( 't', 0)->text, 't1', 'index');
is( $t->index( 't', 1)->text, 't2', 'index');
is_undef( $t->index( 't', 2), 'index');
is( $t->index( 't', -1)->text, 't2', 'index');
my $index= $t->index( 't');
is( $index->[0]->text, 't1', 'index');
is( $index->[ 1]->text, 't2', 'index');
is_undef( $index->[ 2], 'index');
is( $index->[-1]->text, 't2', 'index');
}
{ my $doc=q{t1t2};
my $t= XML::Twig->new( index => { target => 't' })->parse( $doc);
is( $t->index( 'target', 0)->text, 't1', 'index');
is( $t->index( 'target', 1)->text, 't2', 'index');
is_undef( $t->index( 'target', 2), 'index');
is( $t->index( 'target', -1)->text, 't2', 'index');
my $index= $t->index( 'target');
is( $index->[0]->text, 't1', 'index');
is( $index->[ 1]->text, 't2', 'index');
is_undef( $index->[ 2], 'index');
is( $index->[-1]->text, 't2', 'index');
}
# test the remove_cdata option
{ my $doc = q{]]>};
my $escaped_doc= q{<tag&>};
my $t= XML::Twig->new( remove_cdata => 1)->parse( $doc);
is( $t->sprint, $escaped_doc, 'remove_cdata on');
$t= XML::Twig->new( remove_cdata => 0)->parse( $doc);
is( $t->sprint, $doc, 'remove_cdata off');
}
# test the create_accessors method
if( $] < 5.006)
{ skip( 11 => "create_accessors not tested with perl < 5.006"); }
else
{ my $doc= '';
my $t= XML::Twig->new->parse( $doc);
$t->create_accessors( qw(att1 att2));
my $root= $t->root;
is( $root->att1, 1, 'attribute getter');
$root->att1( 2);
is( $root->att1, 2, 'attribute setter');
eval '$root->att1=3'; # eval'ed to keep 5.005 from barfing
is( $root->att1, 3, 'attribute as lvalue');
eval '$root->att1++'; # eval'ed to keep 5.005 from barfing
is( $root->att1, 4, 'attribute as lvalue (++)');
is( $root->att1, $root->att( 'att1'), 'check with regular att method');
eval { $^W=0; $root->att3; $^W=1; };
matches( $@, q{^Can't locate object method "att3" via package "XML::Twig::Elt" }, 'unknow accessor');
is( $root->att2, undef, 'get non-existent att');
$root->att2( 'bar');
is( $root->att2, "bar", 'get non-existent att');
is( $t->sprint, '', 'final output');
eval { $t->create_accessors( 'tag'); };
matches( $@, q{^attempt to redefine existing method tag using att_accessors }, 'duplicate accessor');
$@='';
eval { XML::Twig->create_accessors( 'att2'); };
is( $@, '', 'redefining existing accessor');
}
{ # test embedded comments/pis
foreach my $doc (
q{text },
q{textmore},
q{textmore},
q{textmoremore2},
q{moremore2},
q{},
q{tatatoto},
q{tata <toto <},
q{textmore & even moremore2},
q{text },
q{ more more2 },
q{ more more2},
)
{ my $t= XML::Twig->new->parse( $doc);
is( $t->sprint, $doc, "comment within pcdata ($doc)");
my $t2= XML::Twig->new( keep_encoding => 1)->parse( $doc);
is( $t2->sprint, $doc, "comment within pcdata in keep encoding mode($doc)");
my $doc_pi= $doc;
$doc_pi=~ s{}{?>}g;
my $t3= XML::Twig->new->parse( $doc_pi);
is( $t3->sprint, $doc_pi, "pi within pcdata ($doc_pi)");
my $t4= XML::Twig->new( keep_encoding => 1)->parse( $doc_pi);
is( $t4->sprint, $doc_pi, "pi within pcdata in keep encoding mode($doc_pi)");
}
}
{ # test processing of embedded comments/pis
my $doc= q{foobarfoobar};
my $t= XML::Twig->new->parse( $doc);
my @elt= $t->findnodes( '//elt[string()="foobar"]');
is( scalar( @elt), 2, 'searching on text with embedded comments');
foreach my $elt (@elt) { $elt->set_text( 'toto'); }
is( $t->sprint, q{totototo}, "set_text");
my $t2= XML::Twig->new( keep_encoding => 1)->parse( $doc);
@elt= $t2->findnodes( '//elt[string()="foobar"]');
is( scalar( @elt), 2, 'searching on text with embedded comments');
foreach my $elt (@elt) { $elt->set_text( 'toto'); }
is( $t2->sprint, q{totototo}, "set_text");
}
XML-Twig-3.52/t/xmlxpath_12axisdescendant.t 0000755 0001750 0001750 00000001155 12732215763 021007 0 ustar mrodrigu mrodrigu #!/usr/bin/perl -w
use strict;
use FindBin qw($Bin); BEGIN { unshift @INC, $Bin; } use xmlxpath_tools;
use Test;
plan( tests => 6);
use XML::Twig::XPath;
ok(1);
my $t= XML::Twig::XPath->new->parse( \*DATA);
ok( $t);
my @nodes;
@nodes = $t->findnodes( '/descendant::*');
ok(@nodes, 11);
@nodes = $t->findnodes( '/AAA/BBB/descendant::*');
ok(@nodes, 4);
@nodes = $t->findnodes( '//CCC/descendant::*');
ok(@nodes, 6);
@nodes = $t->findnodes( '//CCC/descendant::DDD');
ok(@nodes, 3);
exit 0;
__DATA__
XML-Twig-3.52/t/test2_2.res 0000644 0001750 0001750 00000002321 13015347616 015521 0 ustar mrodrigu mrodrigu
]>
S1 I1S1 I2S1 TitleS1 P1S2 P2Note P1S1 para 3S2 introS2 TitleS2 P1S2 P2S2 P3Annex TitleAnnex P1Annex P2