####
####
//propname
####
//DAV:propname
####
/propfind/propname
####
/DAV:propfind/DAV:propname
####
#!/usr/bin/perl -w
use strict;
use XML::LibXML;
sub testfn {
my $content = shift or die;
my $xpath = shift or die;
$|++;
my $parser = XML::LibXML->new();
my $dom = $parser->parse_string($content);
my @propfind = ();
@propfind = $dom->findnodes($xpath);
print ref($dom)."::findnodes('$xpath') (NOT XPathContext) ".
scalar(@propfind)." nodes\n";
my $xc = XML::LibXML::XPathContext->new($dom);
$xc->registerNs('D', 'DAV:');
@propfind = $xc->findnodes($xpath);
print ref($xc)."::findnodes('$xpath') ".scalar(@propfind)." nodes\n";
}
# Example from RFC4918
my $txt1 = '
';
my $txt2 = '
';
my $xpath1 = '/DAV:propfind/DAV:propname';
my $xpath2 = '/propfind/propname';
my $xpath3 = '/D:propfind/D:propname';
print "\$txt1\n".$txt1."\n";
print "\$txt1 \$xpath1 \n";
eval {
&testfn($txt1, $xpath1);
};
if($@){
print "Failed \$xpath $xpath1\n";
}
print "\$txt1 \$xpath2 \n";
eval{
&testfn($txt1, $xpath2);
};
if($@){
print "Failed \$xpath $xpath2\n";
}
print "\$txt1 \$xpath3 \n";
eval{
&testfn($txt1, $xpath3);
};
if($@){
print "Failed \$xpath $xpath3\n";
}
print "\$txt2\n".$txt2."\n";
print "\$txt2 \$xpath1 \n";
eval{
&testfn($txt2, $xpath1);
};
if($@){
print "Failed \$xpath $xpath1\n";
}
print "\$txt2 \$xpath2 \n";
eval {
&testfn($txt2, $xpath2);
};
if($@){
print "Failed \$xpath $xpath2\n";
}
print "\$txt2 \$xpath3 \n";
eval {
&testfn($txt2, $xpath3);
};
if($@){
print "Failed \$xpath $xpath3\n";
}
####
$txt1
$txt1 $xpath1
Failed $xpath /DAV:propfind/DAV:propname
$txt1 $xpath2
XML::LibXML::Document::findnodes('/propfind/propname') (NOT XPathContext) 0 nodes
XML::LibXML::XPathContext::findnodes('/propfind/propname') 0 nodes
$txt1 $xpath3
XML::LibXML::Document::findnodes('/D:propfind/D:propname') (NOT XPathContext) 1 nodes
XML::LibXML::XPathContext::findnodes('/D:propfind/D:propname') 1 nodes
$txt2
$txt2 $xpath1
Failed $xpath /DAV:propfind/DAV:propname
$txt2 $xpath2
XML::LibXML::Document::findnodes('/propfind/propname') (NOT XPathContext) 0 nodes
XML::LibXML::XPathContext::findnodes('/propfind/propname') 0 nodes
$txt2 $xpath3
Failed $xpath /D:propfind/D:propname