XML-DOM-XPath-0.14/0000755000175000017500000000000011000634325013771 5ustar mrodrigumrodriguXML-DOM-XPath-0.14/t/0000755000175000017500000000000011000634325014234 5ustar mrodrigumrodriguXML-DOM-XPath-0.14/t/pod_coverage.t0000644000175000001440000000041510470024164016367 0ustar mrodriguusers# $Id: pod_coverage.t,v 1.1 2005/10/18 08:37:22 mrodrigu Exp $ eval "use Test::Pod::Coverage 1.00 tests => 1"; if( $@) { print "1..1\nok 1\n"; warn "Test::Pod::Coverage 1.00 required for testing POD coverage"; exit; } pod_coverage_ok( "XML::DOM::XPath"); XML-DOM-XPath-0.14/t/xmlxpath_30lang.t0000644000175000001440000000072310470024164016745 0ustar mrodriguusers# $Id: xmlxpath_30lang.t,v 1.1 2003/12/04 22:46:57 mrodrigu Exp $ use Test; plan( tests => 4); use XML::DOM::XPath; ok(1); my $parser= XML::DOM::Parser->new; my $t= $parser->parse( \*DATA); ok( $t); my @en = $t->findnodes( '//*[lang("en")]'); ok(@en, 2); my @de = $t->findnodes( '//content[lang("de")]'); ok(@de, 1); __DATA__ Here we go... und hier deutschsprachiger Text :-) XML-DOM-XPath-0.14/t/non_ascii.xml0000644000175000001440000000005610470024164016232 0ustar mrodriguusers XML-DOM-XPath-0.14/t/xmlxpath_22name_select.t0000644000175000001440000000062410470024164020304 0ustar mrodriguusers# $Id: xmlxpath_22name_select.t,v 1.1.1.1 2003/12/04 20:40:43 mrodrigu Exp $ use Test; plan( tests => 4); use XML::DOM::XPath; ok(1); my $parser= XML::DOM::Parser->new; my $t= $parser->parse( \*DATA); ok( $t); my @nodes; @nodes = $t->findnodes( '//*[name() = /AAA/SELECT]'); ok(@nodes, 2); ok($nodes[0]->getName, "BBB"); __DATA__ XML-DOM-XPath-0.14/t/test_non_ascii.t0000644000175000001440000000350710746362714016754 0ustar mrodriguusers#!/usr/bin/perl -w use strict; # $Id: test_non_ascii.t,v 1.2 2005/10/18 08:37:22 mrodrigu Exp $ use Test::More tests => 10; use XML::DOM::XPath; use encoding 'utf8'; my $display_warning=0; { my $dom = XML::DOM::Parser->new(); my $doc = $dom->parsefile( "t/non_ascii.xml"); if( !$doc->toString eq "\n") { $display_warning=1; } is( $doc->toString, "\n",'toString (on file)'); is( $doc->findvalue( '//char'), "bü", "findvalue( '//char') (on file)"); is( $doc->findnodes_as_string( '//char'), '', "findnodes_as_string( '//char') (on file)"); is( $doc->findvalue( '//ent'), 'aü', "findvalue( '//ent') (on file)"); is( $doc->findnodes_as_string( '//ent'), '', "findnodes_as_string( '//ent') (on file)"); } { my $xmlStr = q{}; my $dom = XML::DOM::Parser->new(); my $doc = $dom->parse($xmlStr); is( $doc->toString, qq{\n},'toString (on string)'); is( $doc->findvalue( '//char'), 'bü', "findvalue( '//char') (on string)"); is( $doc->findnodes_as_string( '//char'), qq{}, "findnodes_as_string( '//char') (on string)"); is( $doc->findvalue( '//ent'), qq{aü}, "findvalue( '//ent') (on string)"); is( $doc->findnodes_as_string( '//ent'), qq{}, "findnodes_as_string( '//ent') (on string)"); } if( $display_warning) { warn "One possible reason why this test might fail is if XML::Parser and XML::DOM were\n", "installed with a different version of perl, compiled with a different set of options.\n", "For example upgrading Ubuntu from Dapper Drake to Edgy Eft will cause this test to fail.\n", "Re-installing XML::Parser and XML::DOM will fix the problem.\n" ; } XML-DOM-XPath-0.14/t/xmlxpath_21allnodes.t0000644000175000001440000000232610470024164017626 0ustar mrodriguusers# $Id: xmlxpath_21allnodes.t,v 1.1.1.1 2003/12/04 20:40:43 mrodrigu Exp $ use Test; plan( tests => 11); use XML::DOM::XPath; ok(1); my $parser= XML::DOM::Parser->new; my $t= $parser->parse( \*DATA); ok( $t); my @nodes; @nodes = $t->findnodes( '//GGG/ancestor::*'); ok(@nodes, 4); @nodes = $t->findnodes( '//GGG/descendant::*'); ok(@nodes, 3); @nodes = $t->findnodes( '//GGG/following::*'); ok(@nodes, 3); ok($nodes[0]->getName, "VVV"); @nodes = $t->findnodes( '//GGG/preceding::*'); ok(@nodes, 5); ok($nodes[0]->getName, "BBB"); # document order, not HHH @nodes = $t->findnodes( '//GGG/self::*'); ok(@nodes, 1); ok($nodes[0]->getName, "GGG"); @nodes = $t->findnodes( '//GGG/ancestor::* | //GGG/descendant::* | //GGG/following::* | //GGG/preceding::* | //GGG/self::*'); ok(@nodes, 16); __DATA__ XML-DOM-XPath-0.14/t/xmlxpath_15axisfol_sib.t0000644000175000001440000000110710470024164020326 0ustar mrodriguusers# $Id: xmlxpath_15axisfol_sib.t,v 1.1.1.1 2003/12/04 20:40:43 mrodrigu Exp $ use Test; plan( tests => 6); use XML::DOM::XPath; ok(1); my $parser= XML::DOM::Parser->new; my $t= $parser->parse( \*DATA); ok( $t); my @nodes; @nodes = $t->findnodes( '/AAA/BBB/following-sibling::*'); ok(@nodes, 2); ok($nodes[1]->getName, "CCC"); # test document order @nodes = $t->findnodes( '//CCC/following-sibling::*'); ok(@nodes, 3); ok($nodes[1]->getName, "FFF"); __DATA__ XML-DOM-XPath-0.14/t/xmlxpath_05attrib.t0000644000175000001440000000102410470024164017306 0ustar mrodriguusers# $Id: xmlxpath_05attrib.t,v 1.1.1.1 2003/12/04 20:40:43 mrodrigu Exp $ use Test; plan( tests => 6); use XML::DOM::XPath; ok(1); my $parser= XML::DOM::Parser->new; my $t= $parser->parse( \*DATA); ok( $t); my @ids = $t->findnodes( '//BBB[@id]'); ok(@ids, 2); my @names = $t->findnodes( '//BBB[@name]'); ok(@names, 1); my @attribs = $t->findnodes( '//BBB[@*]'); ok(@attribs, 3); my @noattribs = $t->findnodes( '//BBB[not(@*)]'); ok(@noattribs, 1); __DATA__ XML-DOM-XPath-0.14/t/xmlxpath_13axisparent.t0000644000175000001440000000066310470024164020206 0ustar mrodriguusers# $Id: xmlxpath_13axisparent.t,v 1.1.1.1 2003/12/04 20:40:43 mrodrigu Exp $ use Test; plan( tests => 4); use XML::DOM::XPath; ok(1); my $parser= XML::DOM::Parser->new; my $t= $parser->parse( \*DATA); ok( $t); my @nodes; @nodes = $t->findnodes( '//DDD/parent::*'); ok(@nodes, 4); ok($nodes[3]->getName, "EEE"); __DATA__ XML-DOM-XPath-0.14/t/xmlxpath_16axisprec_sib.t0000644000175000001440000000157610470024164020512 0ustar mrodriguusers# $Id: xmlxpath_16axisprec_sib.t,v 1.1.1.1 2003/12/04 20:40:43 mrodrigu Exp $ use Test; use Test; plan( tests => 7); use XML::DOM::XPath; ok(1); my $parser= XML::DOM::Parser->new; my $t= $parser->parse( \*DATA); ok( $t); my @nodes; @nodes = $t->findnodes( '/AAA/XXX/preceding-sibling::*'); ok(@nodes, 1); ok($nodes[0]->getName, "BBB"); @nodes = $t->findnodes( '//CCC/preceding-sibling::*'); ok(@nodes, 4); @nodes = $t->findnodes( '/AAA/CCC/preceding-sibling::*[1]'); ok($nodes[0]->getName, "XXX"); @nodes = $t->findnodes( '/AAA/CCC/preceding-sibling::*[2]'); ok($nodes[0]->getName, "BBB"); __DATA__ XML-DOM-XPath-0.14/t/xmlxpath_03star.t0000644000175000001440000000072410470024164016776 0ustar mrodriguusersuse Test; plan( tests => 5); use XML::DOM::XPath; ok(1); my $parser= XML::DOM::Parser->new; my $t= $parser->parse( \*DATA); ok( $t); my @nodes; @nodes = $t->findnodes( '/AAA/CCC/DDD/*'); ok(@nodes, 4); @nodes = $t->findnodes( '/*/*/*/BBB'); ok(@nodes, 5); @nodes = $t->findnodes( '//*'); ok(@nodes, 17); __DATA__ XML-DOM-XPath-0.14/t/xmlxpath_17axisfollowing.t0000644000175000001440000000127410470024164020720 0ustar mrodriguusers# $Id: xmlxpath_17axisfollowing.t,v 1.1.1.1 2003/12/04 20:40:43 mrodrigu Exp $ use Test; use Test; plan( tests => 4); use XML::DOM::XPath; ok(1); my $parser= XML::DOM::Parser->new; my $t= $parser->parse( \*DATA); ok( $t); my @nodes; @nodes = $t->findnodes( '/AAA/XXX/following::*'); ok(@nodes, 2); @nodes = $t->findnodes( '//ZZZ/following::*'); ok(@nodes, 12); __DATA__ XML-DOM-XPath-0.14/t/xmlxpath_04pos.t0000644000175000001440000000065410470024164016631 0ustar mrodriguusers# $Id: xmlxpath_04pos.t,v 1.1.1.1 2003/12/04 20:40:43 mrodrigu Exp $ use Test; use Test; plan( tests => 4); use XML::DOM::XPath; ok(1); my $parser= XML::DOM::Parser->new; my $t= $parser->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"); __DATA__ XML-DOM-XPath-0.14/t/pod.t0000644000175000001440000000022010470024164014506 0ustar mrodriguuserseval "use Test::Pod 1.00"; if( $@) { print "1..1\nok 1\n"; warn "skipping, Test::Pod required\n"; } else { all_pod_files_ok( ); } exit 0; XML-DOM-XPath-0.14/t/1.t0000644000175000001440000000072210470024163014072 0ustar mrodriguusers# Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl 1.t' ######################### # change 'tests => 1' to 'tests => last_test_to_print'; use Test::More tests => 1; BEGIN { use_ok('XML::DOM::XPath') }; ######################### # Insert your test code below, the Test::More module is use()ed here so read # its man page ( perldoc Test::More ) for help writing this test script. XML-DOM-XPath-0.14/t/xmlxpath_02descendant.t0000644000175000001440000000070310470024164020131 0ustar mrodriguusers#!/usr/bin/perl -w use strict; # $Id: xmlxpath_02descendant.t,v 1.1.1.1 2003/12/04 20:40:43 mrodrigu Exp $ use Test; plan( tests => 4); use XML::DOM::XPath; ok(1); my $parser= XML::DOM::Parser->new; my $t= $parser->parse( \*DATA); ok($t); my @bbb = $t->findnodes('//BBB'); ok(@bbb, 5); my @subbbb = $t->findnodes('//DDD/BBB'); ok(@subbbb, 3); __DATA__ XML-DOM-XPath-0.14/t/xmlxpath_09a_string_length.t0000644000175000001440000000125510470024164021202 0ustar mrodriguusers# $Id: xmlxpath_09a_string_length.t,v 1.1.1.1 2003/12/04 20:40:43 mrodrigu Exp $ use Test; plan ( tests => 6); use XML::DOM::XPath; ok(1); my $doc_one = qq|para one|; my $parser= XML::DOM::Parser->new; my $t= $parser->parse( $doc_one); ok( $t); my $doc_one_chars = $t->find( 'string-length(/doc/text())'); ok($doc_one_chars == 0, 1); my $doc_two = qq| para one has bold text |; $t= $parser->parse( $doc_two); ok( $t); my $doc_two_chars = $t->find( 'string-length(/doc/text())'); ok($doc_two_chars == 3, 1); my $doc_two_para_chars = $t->find( 'string-length(/doc/para/text())'); ok($doc_two_para_chars == 13, 1); XML-DOM-XPath-0.14/t/xmlxpath_01basic.t0000644000175000001440000000106710470024164017105 0ustar mrodriguusers#!/usr/bin/perl -w use strict; # $Id: xmlxpath_01basic.t,v 1.1.1.1 2003/12/04 20:40:43 mrodrigu Exp $ use Test; plan( tests => 5); use XML::DOM::XPath; ok(1); my $parser= XML::DOM::Parser->new; my $t= $parser->parse( \*DATA); ok($t); my @root = $t->findnodes('/AAA'); ok(@root, 1); my @ccc = $t->findnodes('/AAA/CCC'); ok(@ccc, 3); my @bbb = $t->findnodes('/AAA/DDD/BBB'); ok(@bbb, 2); __DATA__ Text XML-DOM-XPath-0.14/t/xmlxpath_12axisdescendant.t0000644000175000001440000000114710470024164021022 0ustar mrodriguusers# $Id: xmlxpath_12axisdescendant.t,v 1.1.1.1 2003/12/04 20:40:43 mrodrigu Exp $ use Test; use Test; plan( tests => 6); use XML::DOM::XPath; ok(1); my $parser= XML::DOM::Parser->new; my $t= $parser->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); __DATA__ XML-DOM-XPath-0.14/t/xmlxpath_10pipe.t0000644000175000001440000000102010470024164016746 0ustar mrodriguusers# $Id: xmlxpath_10pipe.t,v 1.2 2004/07/21 12:21:31 mrodrigu Exp $ use Test; plan( tests => 6); use XML::DOM::XPath; ok(1); my $parser= XML::DOM::Parser->new; my $t= $parser->parse( \*DATA); ok( $t); my @nodes; @nodes = $t->findnodes( '//CCC | //BBB'); ok(@nodes, 3); ok($nodes[0]->getName, "BBB"); # test document order @nodes = $t->findnodes( '/AAA/EEE | //BBB'); ok(@nodes, 2); @nodes = $t->findnodes( '/AAA/EEE | //DDD/CCC | /AAA | //BBB'); ok(@nodes, 4); __DATA__ XML-DOM-XPath-0.14/t/xmlxpath_09string_length.t0000644000175000001440000000102310470024164020673 0ustar mrodriguusers# $Id: xmlxpath_09string_length.t,v 1.1.1.1 2003/12/04 20:40:43 mrodrigu Exp $ use Test; use Test; plan( tests => 5); use XML::DOM::XPath; ok(1); my $parser= XML::DOM::Parser->new; my $t= $parser->parse( \*DATA); ok( $t); my @nodes; @nodes = $t->findnodes( '//*[string-length(name()) = 3]'); ok(@nodes, 2); @nodes = $t->findnodes( '//*[string-length(name()) < 3]'); ok(@nodes, 2); @nodes = $t->findnodes( '//*[string-length(name()) > 3]'); ok(@nodes, 3); __DATA__ XML-DOM-XPath-0.14/t/xmlxpath_23func.t0000644000175000001440000000140310470024164016755 0ustar mrodriguusers# $Id: xmlxpath_23func.t,v 1.1.1.1 2003/12/04 20:40:43 mrodrigu Exp $ use Test; plan( tests => 5); use XML::DOM::XPath; ok(1); my $parser= XML::DOM::Parser->new; my $t= $parser->parse( \*DATA); ok( $t); my @nodes; @nodes = $t->findnodes( '//BBB[position() mod 2 = 0 ]'); ok(@nodes, 4); @nodes = $t->findnodes('//BBB [ position() = floor(last() div 2 + 0.5) or position() = ceiling(last() div 2 + 0.5) ]'); ok(@nodes, 2); @nodes = $t->findnodes('//CCC [ position() = floor(last() div 2 + 0.5) or position() = ceiling(last() div 2 + 0.5) ]'); ok(@nodes, 1); __DATA__ XML-DOM-XPath-0.14/t/xmlxpath_06attrib_val.t0000644000175000001440000000077510470024164020165 0ustar mrodriguusers# $Id: xmlxpath_06attrib_val.t,v 1.1.1.1 2003/12/04 20:40:43 mrodrigu Exp $ use Test; plan( tests => 5); use XML::DOM::XPath; ok(1); my $parser= XML::DOM::Parser->new; my $t= $parser->parse( \*DATA); ok( $t); my @nodes; @nodes = $t->findnodes( '//BBB[@id = "b1"]'); ok(@nodes, 1); @nodes = $t->findnodes( '//BBB[@name = "bbb"]'); ok(@nodes, 1); @nodes = $t->findnodes( '//BBB[normalize-space(@name) = "bbb"]'); ok(@nodes, 2); __DATA__ XML-DOM-XPath-0.14/t/test_bugs.t0000644000175000001440000001362711000633021015726 0ustar mrodriguusers#!/usr/bin/perl -w use strict; # $Id: test_bugs.t,v 1.6 2005/03/08 09:08:42 mrodrigu Exp $ use Test::More tests => 21; use XML::DOM::XPath; ok(1, "use XML::DOM::XPath"); { # bug 1 # bug on getAttributes: problem when an element has no attribute # found by Harry Moreau my $parser= XML::DOM::Parser->new; my $dom= $parser->parse( 'elt 1elt 2'); my @nodes= $dom->findnodes( '//elt[@id="elt1"]'); is( scalar @nodes => 1, "bug 1: result number"); is( $nodes[0]->toString => 'elt 1', "bug 1: result content"); } { # RT #8167 : toString did not work on a document # found by Ben Hsing my $parser= XML::DOM::Parser->new; my $xml= "foo\n"; my $dom= $parser->parse( $xml); is( $dom->toString, $xml, "toString on a whole document"); } # RT #8977 : could not call XPath methods on an XML::DOM::Document before the parse # because new did not create the xp object attached to the XML::DOM::Document { my $xml = XML::DOM::Document->new; my $root = $xml->createElement('root'); $xml->appendChild($root); ok( $xml->exists('root'), "can call XPath methods on an XML::DOM::Document before the parse"); } # RT#11648: some xpath expressions containing '>', '>=', '<', '<=' operators trigger an error: # Can't locate object method "to_number" via package "XML::DOM::Element" ... # found and test case by a guest on RT { my $xmlStr = q{131 2510 }; my $dom = XML::DOM::Parser->new(); my $doc = $dom->parse($xmlStr); my @prices= map { $_->getAttribute( 'id')} $doc->findnodes('/d/e[f<1.9]'); is( join( ':' => @prices), 'e1:e3', "using number comparison on elements"); my $prices= $doc->findvalue('/d/e[f<2]/@id'); if( $prices eq 'e1e3e4') { warn " warning: the version of XPath you are using has a bug in the way it\n", " handles numeric comparisons.\n", " read the bug description: http://rt.cpan.org/NoAuth/Bug.html?id=6363\n", " if an XML::XPath version with a fix for the bug is not yet available,\n", " you can get a patched version: http://xmltwig.com/xml-xpath-patched/\n", ; ok( 1, "using number comparison on elements (XPath bug found)"); } else { is( $prices, 'e1e3', "using number comparison on elements"); } $prices= $doc->findvalue('/d/e[f<2.5]/@id'); is( $prices, 'e1e3e4', "using number comparison on elements"); is( $doc->findvalue('/d/e[@nb>=2]/@id'), 'e2e3e4e5e6', "using number comparison on attributes"); my @nodes= $doc->findnodes( '/d/e/@id'); } { #RT 20884: //@* dies (needed getAttributes on XML::DOM::Document node type) my $res= XML::DOM::Parser->new ->parse('') ->findvalue('//@*'); is( $res, 'e0e1e2e3', '//@*'); } { #RT 20884: //comment() dies (missing isNode methods) my $doc= XML::DOM::Parser->new ->parse(''); is( $doc->findvalue( '//comment()'), 'c1c2', '//comment()'); is( $doc->findvalue( '//processing-instruction("t1")'), 'd1d3', '//processing-instruction( "t1")'); # bug in XML::XPath my $pis= $doc->findvalue( '//processing-instruction()'); if( $pis eq '') { warn " warning: the version of XPath you are using has a bug in the way it\n", " handles the processing-instruction() selector'.\n", " if an XML::XPath version with a fix for the bug is not yet available,\n", " you can get a patched version: http://xmltwig.com/xml-xpath-patched/\n", ; ok( 1, "testing '//processing-instruction()' (XPath bug found)"); } else { is( $doc->findvalue( '//processing-instruction()'), 'd1d2d3', '//processing-instruction()'); } } { my $xml=qq| |; my $xp = XML::DOM::Parser->new->parsestring($xml); is( $xp->findvalue( 'count( //component)'), 3, 'count on its own'); is( 2 * $xp->findvalue( 'count( //component)'), 6, '2 * count'); is( $xp->findvalue( 'count( //component)') * 2, 6, 'count * 2'); { my $component= ($xp->findnodes ('//structure//assessments/component'))[0]; my $id = $component->findvalue ('@id'); my $weight= $component->findvalue ('@weight'); my $res= 100 * $weight; # this is where things failed is( $res, 4000, 'findvalue result used in an multiplication'); } { my $weight=($xp->findnodes_as_strings ('//structure//assessments/component/@weight'))[0]; my $res= 100 * $weight; # this is where things failed is( $res, 4000, 'findvalue result used in an multiplication'); } } { my $xml=qq| I start the text here, I break the line and I go on, I twinkle and then I go on again. This is not a new paragraph.This is a new paragraph and this word has a preceding sibling. |; my $xp = XML::DOM::Parser->new->parsestring( $xml); ok($xp); # Debian bug #187583, http://bugs.debian.org/187583 # Check that evaluation doesn't lose the context information my $nodes = $xp->find("text/para/node()[position()=last() and preceding-sibling::important]"); ok("$nodes", " has a preceding sibling."); $nodes = $xp->find("text/para/node()[preceding-sibling::important and position()=last()]"); ok("$nodes", " has a preceding sibling."); } XML-DOM-XPath-0.14/t/xmlxpath_07count.t0000644000175000001440000000111210470024164017151 0ustar mrodriguusers# $Id: xmlxpath_07count.t,v 1.1.1.1 2003/12/04 20:40:43 mrodrigu Exp $ use Test; plan( tests => 7); use XML::DOM::XPath; ok(1); my $parser= XML::DOM::Parser->new; my $t= $parser->parse( \*DATA); ok( $t); my @nodes; @nodes = $t->findnodes( '//*[count(BBB) = 2]'); ok($nodes[0]->getName, "DDD"); @nodes = $t->findnodes( '//*[count(*) = 2]'); ok(@nodes, 2); @nodes = $t->findnodes( '//*[count(*) = 3]'); ok(@nodes, 2); ok($nodes[0]->getName, "AAA"); ok($nodes[1]->getName, "CCC"); __DATA__ XML-DOM-XPath-0.14/t/xmlxpath_19axisd_or_s.t0000644000175000001440000000077710470024164020176 0ustar mrodriguusers# $Id: xmlxpath_19axisd_or_s.t,v 1.1.1.1 2003/12/04 20:40:43 mrodrigu Exp $ use Test; plan( tests => 4); use XML::DOM::XPath; ok(1); my $parser= XML::DOM::Parser->new; my $t= $parser->parse( \*DATA); ok( $t); my @nodes; @nodes = $t->findnodes( '/AAA/XXX/descendant-or-self::*'); ok(@nodes, 8); @nodes = $t->findnodes( '//CCC/descendant-or-self::*'); ok(@nodes, 4); __DATA__ XML-DOM-XPath-0.14/t/xmlxpath_25scope.t0000644000175000001440000000061210470024164017136 0ustar mrodriguusers# $Id: xmlxpath_25scope.t,v 1.1.1.1 2003/12/04 20:40:43 mrodrigu Exp $ use strict; use Test; plan( tests => 4); use XML::DOM::XPath; ok(1); eval { # Removing the 'my' makes this work?!? my $parser= XML::DOM::Parser->new; my $t= $parser->parse( ''); ok( $t); $t->findnodes( '/test'); ok(1); die "This should be caught\n"; }; if ($@) { ok(1); } else { ok(0); } XML-DOM-XPath-0.14/t/xmlxpath_28ancestor2.t0000644000175000001440000000220510470024164017730 0ustar mrodriguusers# $Id: xmlxpath_28ancestor2.t,v 1.1 2003/12/04 22:46:57 mrodrigu Exp $ use Test; plan( tests => 5); use XML::DOM::XPath; ok(1); my $parser= XML::DOM::Parser->new; my $t= $parser->parse( \*DATA); ok( $t); my @nodes; @nodes = $t->findnodes( '//Footnote'); ok(@nodes, 1); my $footnote = $nodes[0]; #@nodes = $footnote->findnodes('ancestor::*', $t); @nodes = $footnote->findnodes( 'ancestor::*'); ok(@nodes, 3); @nodes = $footnote->findnodes('ancestor::text:footnote', $t); ok(@nodes, 1); __DATA__ 2 AxKit is very flexible in how it lets you transform the XML on the server, and there are many modules you can plug in to AxKit to allow you to do these transformations. For this reason, the AxKit installation does not mandate any particular modules to use, instead it will simply suggest modules that might help when you install AxKit. XML-DOM-XPath-0.14/t/xmlxpath_08name.t0000644000175000001440000000102010470024164016740 0ustar mrodriguusers# $Id: xmlxpath_08name.t,v 1.1.1.1 2003/12/04 20:40:43 mrodrigu Exp $ use Test; plan( tests => 5); use XML::DOM::XPath; ok(1); my $parser= XML::DOM::Parser->new; my $t= $parser->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); __DATA__ XML-DOM-XPath-0.14/t/xmlxpath_20axisa_or_s.t0000644000175000001440000000100310470024164020142 0ustar mrodriguusers# $Id: xmlxpath_20axisa_or_s.t,v 1.1.1.1 2003/12/04 20:40:43 mrodrigu Exp $ use Test; plan( tests => 4); use XML::DOM::XPath; ok(1); my $parser= XML::DOM::Parser->new; my $t= $parser->parse( \*DATA); ok( $t); my @nodes; @nodes = $t->findnodes( '/AAA/XXX/DDD/EEE/ancestor-or-self::*'); ok(@nodes, 4); @nodes = $t->findnodes( '//GGG/ancestor-or-self::*'); ok(@nodes, 5); __DATA__ XML-DOM-XPath-0.14/t/xmlxpath_29desc_with_predicate.t0000644000175000001440000000066110470024164022026 0ustar mrodriguusers# $Id: xmlxpath_29desc_with_predicate.t,v 1.1.1.1 2003/12/04 20:40:43 mrodrigu Exp $ use Test; plan( tests => 4); use XML::DOM::XPath; ok(1); my $parser= XML::DOM::Parser->new; my $t= $parser->parse( \*DATA); ok( $t); my @bbb = $t->findnodes( '/descendant::BBB[1]'); ok(@bbb, 1); ok($bbb[0]->string_value, "OK"); __DATA__ OK NOT OK XML-DOM-XPath-0.14/t/test_xml_xpath_and_xml_dom_xpath.t0000644000175000001440000000104210535311213022533 0ustar mrodriguusers#!/usr/bin/perl -w use strict; # $Id: test_xml_xpath_and_xml_dom_xpath.t,v 1.2 2005/03/07 08:39:13 mrodrigu Exp $ use Test::More tests => 1; use XML::DOM::XPath; unless(eval{require XML::XPath}) { ok(1); exit; } import XML::XPath; my $xml = < EOF my $xp = XML::XPath->new($xml); my $exp = '/school/class/student/@name'; my $nodeSet = $xp->find($exp); is( $nodeSet->size(), 1, "using XML::XPath and XML::DOM::XPath"); XML-DOM-XPath-0.14/t/xmlxpath_26predicate.t0000644000175000001440000000071610470024164017773 0ustar mrodriguusers# $Id: xmlxpath_26predicate.t,v 1.1.1.1 2003/12/04 20:40:43 mrodrigu Exp $ use Test; plan( tests => 4); use XML::DOM::XPath; ok(1); my $parser= XML::DOM::Parser->new; my $t= $parser->parse( \*DATA); ok( $t); my @bbb = $t->findnodes( '//a/b[2]'); ok(@bbb, 2); @bbb = $t->findnodes( '(//a/b)[2]'); ok(@bbb, 1); __DATA__ some 1 value 1 some 2 value 2 XML-DOM-XPath-0.14/t/xmlxpath_14axisancestor.t0000644000175000001440000000103210470024164020523 0ustar mrodriguusers# $Id: xmlxpath_14axisancestor.t,v 1.1.1.1 2003/12/04 20:40:43 mrodrigu Exp $ use Test; plan( tests => 5); use XML::DOM::XPath; ok(1); my $parser= XML::DOM::Parser->new; my $t= $parser->parse( \*DATA); ok( $t); my @nodes; @nodes = $t->findnodes( '/AAA/BBB/DDD/CCC/EEE/ancestor::*'); ok(@nodes, 4); ok($nodes[1]->getName, "BBB"); # test document order @nodes = $t->findnodes( '//FFF/ancestor::*'); ok(@nodes, 5); __DATA__ XML-DOM-XPath-0.14/t/xmlxpath_18axispreceding.t0000644000175000001440000000125510470024164020660 0ustar mrodriguusers# $Id: xmlxpath_18axispreceding.t,v 1.1.1.1 2003/12/04 20:40:43 mrodrigu Exp $ use Test; plan( tests => 4); use XML::DOM::XPath; ok(1); my $parser= XML::DOM::Parser->new; my $t= $parser->parse( \*DATA); ok( $t); my @nodes; @nodes = $t->findnodes( '/AAA/XXX/preceding::*'); ok(@nodes, 4); @nodes = $t->findnodes( '//GGG/preceding::*'); ok(@nodes, 8); __DATA__ XML-DOM-XPath-0.14/t/xmlxpath_24namespaces.t0000644000175000001440000000324410744063145020155 0ustar mrodriguusers#!/usr/bin/perl -w use strict; use Test; plan( tests => 15); use XML::DOM::XPath; ok(1); my $parser= XML::DOM::Parser->new; my $t= $parser->parse( \*DATA); my $node= $t->findvalue( '//attr:node/@attr:findme'); ok( $node, 'someval'); my @nodes; # Do not set namespace prefixes - uses element context namespaces @nodes = $t->findnodes('//foo:foo', $t); # should find foobar.com foos ok( @nodes, 3); @nodes = $t->findnodes('//goo:foo', $t); # should find no foos ok( @nodes, 0); @nodes = $t->findnodes('//foo', $t); # should find default NS foos ok( @nodes, 2); $node= $t->findvalue( '//*[@attr:findme]'); ok( $node, 'attr content'); ok( $t->findvalue('//attr:node/@attr:findme'), 'someval'); ok( $t->findvalue( '//toto'), 'tata'); ok( $t->findvalue( '//toto/@att'), 'tutu'); # Set namespace mappings. $t->set_namespace("foo" => "flubber.example.com"); $t->set_namespace("goo" => "foobar.example.com"); @nodes = $t->findnodes('//foo:foo', $t); # should find flubber.com foos ok( @nodes, 2); @nodes = $t->findnodes('//goo:foo', $t); # should find foobar.com foos ok( @nodes, 3); @nodes = $t->findnodes('//foo', $t); # should find default NS foos ok( @nodes, 2); ok( $t->findvalue('//attr:node/@attr:findme'), 'someval'); ok( $t->findvalue( '//toto'), 'tata'); ok( $t->findvalue( '//toto/@att'), 'tutu'); __DATA__ attr content tata XML-DOM-XPath-0.14/Changes0000644000175000001440000000403011000634064014566 0ustar mrodriguusersRevision history for Perl extension XML::DOM::XPath. $Id: Changes,v 1.8 2005/10/18 08:39:04 mrodrigu Exp $ 0.14 - upgraded dependency to XML::XPathEngine 1.10 - added the findnodes_as_strings method, that returns a list of strings, one for each matching node - fixed RT #29423, test failing on Debian see http://rt.cpan.org/Ticket/Display.html?id=29423 - added tests for bugs fixed in XML::XPathEngine 1.10 0.13 - removed dependency on XML::XPath in tests (spotted by Sendu Bala) - added warning for test failure due to using XML::Parser and XML::DOM from a previous version of perl, compiled with different options (spotted by Tony Awtrey) 0.12 - changed dependency from XML::XPath (which does not seem to be actively maintained) to XML::XPathEngine (which I maintain) - fixed bug in sorting attributes 0.11 - fixed bugs when using a query with //@*, or with //comment(), spotted by Ben Hsing (RT #20884). 0.10 - added pod tests and tests with utf-8 characters 0.09 - allow XML::XPath to be also used (the sort method checks on which type of object it is called), fixes bug RT 11772 0.08 - fixed a bug with XPath expressions using numerical comparison (added the to_number method to XML::DOM::Node) (RT #11648) - tests whether XML::XPath still show the comparison operator bug ( http://rt.cpan.org/NoAuth/Bug.html?id=6363 ) and warn about it in that case. 0.07 - fixed a bug which prevented calling XPath methods on an XML::DOM::Document before the parse (RT #8977) found by Ben Hsing 0.06 - fixed a bug in that prevented toString to work on a document (RT #8167) found by Ben Hsing 0.05 - fixed a bug in getAttributes, when an element does not have an attribute. Thanks to Harry Moreau for the bug report and the patch. 0.04 - fixed docs 0.02 - added namespace support 0.01 Thu Dec 4 14:53:15 2003 - original version; created by h2xs 1.22 with options -A -X -nXML::DOM::XPath --use-new-tests --skip-exporter --skip-autoloader XML-DOM-XPath-0.14/MANIFEST0000644000175000017500000000170710535335170015137 0ustar mrodrigumrodriguChanges Makefile.PL MANIFEST README XPath.pm t/1.t t/test_bugs.t t/xmlxpath_01basic.t t/xmlxpath_02descendant.t t/xmlxpath_03star.t t/xmlxpath_04pos.t t/xmlxpath_05attrib.t t/xmlxpath_06attrib_val.t t/xmlxpath_07count.t t/xmlxpath_08name.t t/xmlxpath_09a_string_length.t t/xmlxpath_09string_length.t t/xmlxpath_10pipe.t t/xmlxpath_12axisdescendant.t t/xmlxpath_13axisparent.t t/xmlxpath_14axisancestor.t t/xmlxpath_15axisfol_sib.t t/xmlxpath_16axisprec_sib.t t/xmlxpath_17axisfollowing.t t/xmlxpath_18axispreceding.t t/xmlxpath_19axisd_or_s.t t/xmlxpath_20axisa_or_s.t t/xmlxpath_21allnodes.t t/xmlxpath_22name_select.t t/xmlxpath_23func.t t/xmlxpath_24namespaces.t t/xmlxpath_25scope.t t/xmlxpath_26predicate.t t/xmlxpath_28ancestor2.t t/xmlxpath_29desc_with_predicate.t t/xmlxpath_30lang.t t/test_xml_xpath_and_xml_dom_xpath.t t/pod.t t/pod_coverage.t t/test_non_ascii.t t/non_ascii.xml META.yml Module meta-data (added by MakeMaker) XML-DOM-XPath-0.14/META.yml0000644000175000017500000000101411000634325015236 0ustar mrodrigumrodrigu--- #YAML:1.0 name: XML-DOM-XPath version: 0.14 abstract: Perl extension to add XPath support to XML::DOM, using XML::XPath engine license: ~ author: - Michel Rodriguez generated_by: ExtUtils::MakeMaker version 6.44 distribution_type: module requires: XML::DOM: 0 XML::XPathEngine: 0.1 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.3.html version: 1.3 XML-DOM-XPath-0.14/XPath.pm0000644000175000001440000002315411000634121014657 0ustar mrodriguusers# $Id: XPath.pm,v 1.11 2005/10/18 08:39:04 mrodrigu Exp $ package XML::DOM::XPath; use strict; use XML::XPathEngine; use XML::DOM; use vars qw($VERSION); $VERSION="0.14"; my $xp_field; # the field in the document that contains the XML::XPathEngine object my $parent_field; # the field in an attribute that contains the parent element BEGIN { # this is probably quite wrong, I have to figure out the internal structure of nodes better $xp_field = 11; $parent_field = 12; } package XML::DOM::Document; sub findnodes { my( $dom, $path)= @_; return $dom->xp->findnodes( $path, $dom); } sub findnodes_as_string { my( $dom, $path)= @_; return $dom->xp->findnodes_as_string( $path, $dom); } sub findnodes_as_strings { my( $dom, $path)= @_; return $dom->xp->findnodes_as_strings( $path, $dom); } sub findvalue { my( $dom, $path)= @_; return $dom->xp->findvalue( $path, $dom); } sub exists { my( $dom, $path)= @_; return $dom->xp->exists( $path, $dom); } sub find { my( $dom, $path)= @_; return $dom->xp->find( $path, $dom); } sub matches { my( $dom, $path)= @_; return $dom->xp->matches( $dom, $path, $dom); } sub set_namespace { my $dom= shift; $dom->xp->set_namespace( @_); } sub cmp { return $_[1]->isa( 'XML::DOM::Document') ? 0 : 1; } sub getRootNode { return $_[0]; } sub xp { return $_[0]->[$xp_field] } { no warnings; # copied from the original DOM package, with the addition of the creation of the XML::XPathEngine object sub new { my ($class) = @_; my $self = bless [], $class; # keep Doc pointer, even though getOwnerDocument returns undef $self->[_Doc] = $self; $self->[_C] = new XML::DOM::NodeList; $self->[$xp_field]= XML::XPathEngine->new(); $self; } } package XML::DOM::Node; sub findnodes { my( $node, $path)= @_; return $node->xp->findnodes( $path, $node); } sub findnodes_as_string { my( $node, $path)= @_; return $node->xp->findnodes_as_string( $path, $node); } sub findvalue { my( $node, $path)= @_; return $node->xp->findvalue( $path, $node); } sub exists { my( $node, $path)= @_; return $node->xp->exists( $path, $node); } sub find { my( $node, $path)= @_; return $node->xp->find( $path, $node); } sub matches { my( $node, $path)= @_; return $node->xp->matches( $node->getOwnerDocument, $path, $node); } sub isCommentNode { 0 }; sub isPINode { 0 }; sub to_number { return XML::XPathEngine::Number->new( shift->string_value); } sub getParent { return $_[0]->getParentNode; } sub getRootNode { return $_[0]->getOwnerDocument; } sub xp { return $_[0]->getOwnerDocument->xp; } # this method exists in XML::DOM but it returns undef, while # XML::XPathEngine needs it, but wants an array... bother! # This method is actually redefined for XML::DOM::Element, but needs # to be here for other types of nodes. { no warnings; sub getAttributes { if( caller(0)!~ m{^XML::XPathEngine}) { return undef; } # XML::DOM else { my @atts= (); return wantarray ? @atts : \@atts; } # XML::XPathEngine } } sub cmp { my( $a, $b)=@_; # easy cases return 0 if( $a == $b); return -1 if( $a->isAncestor($b)); # a starts before b return 1 if( $b->isAncestor($a)); # a starts after b # special case for 2 attributes of the same element # order is dictionary order of the attribute names if( $a->isa( 'XML::DOM::Attr') && $b->isa( 'XML::DOM::Attr')) { if( $a->getParent == $b->getParent) { return $a->getName cmp $b->getName } else { return $a->getParent->cmp( $b->getParent); } } # ancestors does not include the element itself my @a_pile= ($a->ancestors_or_self); my @b_pile= ($b->ancestors_or_self); # the 2 elements are not in the same twig return undef unless( $a_pile[-1] == $b_pile[-1]); # find the first non common ancestors (they are siblings) my $a_anc= pop @a_pile; my $b_anc= pop @b_pile; while( $a_anc == $b_anc) { $a_anc= pop @a_pile; $b_anc= pop @b_pile; } # from there move left and right and figure out the order my( $a_prev, $a_next, $b_prev, $b_next)= ($a_anc, $a_anc, $b_anc, $b_anc); while() { $a_prev= $a_prev->getPreviousSibling || return( -1); return 1 if( $a_prev == $b_next); $a_next= $a_next->getNextSibling || return( 1); return -1 if( $a_next == $b_prev); $b_prev= $b_prev->getPreviousSibling || return( 1); return -1 if( $b_prev == $a_next); $b_next= $b_next->getNextSibling || return( -1); return 1 if( $b_next == $a_prev); } } sub ancestors_or_self { my $node= shift; my @ancestors= ($node); while( $node= $node->getParent) { push @ancestors, $node; } return @ancestors; } sub getNamespace { my $node= shift; my $prefix= shift() || $node->ns_prefix; if( my $expanded= $node->get_namespace( $prefix)) { return XML::DOM::Namespace->new( $prefix, $expanded); } else { return XML::DOM::Namespace->new( $prefix, ''); } } sub getLocalName { my $node= shift; (my $local= $node->getName)=~ s{^[^:]*:}{}; return $local; } sub ns_prefix { my $node= shift; if( $node->getName=~ m{^([^:]*):}) { return $1; } else { return( '#default'); } # should it be '' ? } BEGIN { my %DEFAULT_NS= ( xml => "http://www.w3.org/XML/1998/namespace", xmlns => "http://www.w3.org/2000/xmlns/", ); sub get_namespace { my $node= shift; my $prefix= defined $_[0] ? shift() : $node->ns_prefix; if( $prefix eq "#default") { $prefix=''} my $ns_att= $prefix ? "xmlns:$prefix" : "xmlns"; my $expanded= $DEFAULT_NS{$prefix} || $node->inherit_att( $ns_att) || ''; return $expanded; } } sub inherit_att { my $node= shift; my $att= shift; do { if( ($node->getNodeType == ELEMENT_NODE) && ($node->getAttribute( $att))) { return $node->getAttribute( $att); } } while( $node= $node->getParentNode); return undef; } package XML::DOM::Element; sub getName { return $_[0]->getTagName; } { no warnings; # this method exists in XML::DOM but it returns a NamedNodeMap object # XML::XPathEngine needs it, but wants an array... bother! sub getAttributes { # in any case we need $_[0]->[_A] to be filled $_[0]->[_A] ||= XML::DOM::NamedNodeMap->new (Doc => $_[0]->[_Doc], Parent => $_[0]); if( caller(0)!~ m{^XML::XPathEngine}) { # the original XML::DOM value return $_[0]->[_A]; } else { # this is what XML::XPathEngine needs my $elt= shift; my @atts= grep { ref $_ eq 'XML::DOM::Attr' } values %{$elt->[1]}; $_->[$parent_field]= $elt foreach (@atts); return wantarray ? @atts : \@atts; } } } # nearly straight from XML::XPathEngine sub string_value { my $self = shift; my $string = ''; foreach my $kid ($self->getChildNodes) { if ($kid->getNodeType == ELEMENT_NODE || $kid->getNodeType == TEXT_NODE) { $string .= $kid->string_value; } } return $string; } package XML::DOM::Attr; # needed for the sort sub inherit_att { return $_[0]->getParent->inherit_att( @_); } sub getParent { return $_[0]->[$parent_field]; } sub string_value { return $_[0]->getValue; } sub getData { return $_[0]->getValue; } package XML::DOM::Text; sub string_value { return $_[0]->getData; } package XML::DOM::Comment; sub isCommentNode { 1 }; sub string_value { return $_[0]->getData; } package XML::DOM::ProcessingInstruction; sub isPINode { 1 }; sub isProcessingInstructionNode { 1 }; sub string_value { return $_[0]->getData; } sub value { return $_[0]->getData; } package XML::DOM::Namespace; sub new { my( $class, $prefix, $expanded)= @_; bless { prefix => $prefix, expanded => $expanded }, $class; } sub isNamespaceNode { 1; } sub getPrefix { $_[0]->{prefix}; } sub getExpanded { $_[0]->{expanded}; } sub getValue { $_[0]->{expanded}; } sub getData { $_[0]->{expanded}; } 1; __END__ =head1 NAME XML::DOM::XPath - Perl extension to add XPath support to XML::DOM, using XML::XPath engine =head1 SYNOPSIS use XML::DOM::XPath; my $parser= XML::DOM::Parser->new(); my $doc = $parser->parsefile ("file.xml"); # print all HREF attributes of all CODEBASE elements # compare with the XML::DOM version to see how much easier it is to use my @nodes = $doc->findnodes( '//CODEBASE[@HREF]/@HREF'); print $_->getValue, "\n" foreach (@nodes); =head1 DESCRIPTION XML::DOM::XPath allows you to use XML::XPath methods to query a DOM. This is often much easier than relying only on getElementsByTagName. It lets you use all of the XML::DOM methods. =head1 METHODS Those methods can be applied to a whole dom object or to a node. =head2 findnodes($path) return a list of nodes found by $path. =head2 findnodes_as_string($path) return the nodes found reproduced as XML. The result is not guaranteed to be valid XML though. =head2 findvalue($path) return the concatenation of the text content of the result nodes =head2 exists($path) return true if the given path exists. =head2 matches($path) return true if the node matches the path. =head1 SEE ALSO XML::DOM XML::XPathEngine =head1 AUTHOR Michel Rodriguez, mirod@cpan.org =head1 COPYRIGHT AND LICENSE Copyright 2003 by Michel Rodriguez This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut XML-DOM-XPath-0.14/Makefile.PL0000644000175000001440000000116211000633042015243 0ustar mrodriguusers# $Id: Makefile.PL,v 1.1.1.1 2003/12/04 20:40:43 mrodrigu Exp $ use ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( NAME => 'XML::DOM::XPath', VERSION_FROM => 'XPath.pm', # finds $VERSION PREREQ_PM => { XML::DOM => 0, XML::XPathEngine => 0.10 }, # e.g., Module::Name => 1.1 ($] >= 5.005 ? ## Add these new keywords supported since 5.005 (ABSTRACT_FROM => 'XPath.pm', # retrieve abstract from module AUTHOR => 'Michel Rodriguez ') : ()), ); XML-DOM-XPath-0.14/README0000644000175000001440000000153410470024163014164 0ustar mrodriguusersXML/DOM/XPath ========================== # $Id: README,v 1.1.1.1 2003/12/04 20:40:43 mrodrigu Exp $ XML::DOM::XPath is a helper module for XML::DOM that adds XPath support to it. It uses XML::XPath to resolve the XPath queries In truth this should only be used if you have existing code using XML::DOM. If you start a new project and if you can install XML::LibXML (and libxml2 on which it is based) then you will get a DOM, XPAth support and a lot more power and speed. INSTALLATION To install this module type the following: perl Makefile.PL make make test make install DEPENDENCIES This module requires these other modules and libraries: XML::DOM XML::XPath COPYRIGHT AND LICENCE Copyright (C) 2003 Michel Rodriguez This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.