Skip Menu |
 

This queue is for tickets about the XML-XPath CPAN distribution.

Report information
The Basics
Id: 8784
Status: new
Priority: 0/
Queue: XML-XPath

People
Owner: Nobody in particular
Requestors: mel [...] mitre.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 1.13
Fixed in: (no value)



Subject: mapped prefixes not matched if context is not at root
Download (untitled) / with headers
text/plain 2.9k
XML-XPath version 1.13 on Windows XP SP2 ActiveStte perl v5.8.4 for MSWin32-x86-multi-thread If I map a prefix to a namespace name and then search from the document root for a qualified name with that prefix, the search returns the expected node(s). If I search from that point (i.e., context is at a node), then no results are returned unless I use the prefix used in the instance document. The example code at the end is a modification of the example from bug report #7530, which seems related to this one. Running the code results in the following for me xpath expr: /ns1:AAA/ns3:DDD/name3:BBB val: Text From ns3:BBB xpath expr: /ns1:AAA/ns3:DDD found: ns3:DDD in scope namespace: ns3 is uri:namespace3 name4:BBB: [] ns4:BBB: [Text from ns2:BBB] name3:BBB: [] ns3:BBB: [Text From ns3:BBB] EEE: [Text from EEE] xpath expr: /name1:AAA/name3:DDD/name3:BBB val: Text From ns3:BBB xpath expr: /name1:AAA/name3:DDD found: ns3:DDD in scope namespace: ns3 is uri:namespace3 name4:BBB: [] ns4:BBB: [Text from ns2:BBB] name3:BBB: [] ns3:BBB: [Text From ns3:BBB] EEE: [Text from EEE] ------------------------ use strict; use XML::XPath; my $xp = XML::XPath->new( ioref => *DATA); $xp->set_namespace("name1","uri:namespace1"); $xp->set_namespace("name2","uri:namespace2"); $xp->set_namespace("name3","uri:namespace3"); $xp->set_namespace("name4","uri:namespace4"); # Entry 1: Use prefixes known to be in instance document # Entry 2: Use prefix mapped above to namespace my @items = qw[/ns1:AAA/ns3:DDD /name1:AAA/name3:DDD]; foreach my $item (@items) { print "xpath expr: $item" . "/name3:BBB val: " . $xp->find($item . '/name3:BBB') . "\n"; print "xpath expr: $item \n"; my @nodes = $xp->findnodes($item); foreach my $node (@nodes) { print "\tfound: " . $node->getName . "\n"; my @nsps = $xp->findnodes('namespace::*', $node); foreach my $nsp (@nsps) { print "\t\tin scope namespace: " .$nsp->getPrefix . " is " . $nsp->getExpanded . "\n"; } print "\t\tname4:BBB: [" . $node->findvalue('name4:BBB') . "]\n"; print "\t\tns4:BBB: [" . $node->findvalue('ns4:BBB') . "]\n"; print "\t\tname3:BBB: [" . $node->findvalue('name3:BBB') . "]\n"; print "\t\tns3:BBB: [" . $node->findvalue('ns3:BBB') . "]\n"; print "\t\tEEE: [" . $node->findvalue('EEE') . "]\n"; print "\n"; } } __DATA__ <ns1:AAA xmlns:ns1="uri:namespace1"> <ns1:BBB/> <n2:CCC xmlns:ns2="uri:namespace2"/> <ns1:BBB/> <n2:CCC/> <ns1:BBB/> <!-- comment --> <ns3:DDD xmlns:ns3="uri:namespace3"> <ns4:BBB xmlns:ns4="uri:namespace4">Text from ns2:BBB</ns4:BBB> <ns3:BBB>Text From ns3:BBB</ns3:BBB> <EEE>Text from EEE</EEE> </ns3:DDD> <n2:CCC/> </ns1:AAA>


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.