#!/usr/bin/perl -w
use strict;
use XML::LibXML;
sub doitLX {
my $contentRef = shift or die;
my $content = $$contentRef;
my $xpath = shift or die;
$|++;
my $parser = XML::LibXML->new();
my $dom = $parser->parse_string($content);
my $doc = $dom->documentElement();
my @propfind = ();
eval {
@propfind = $dom->findnodes($xpath);
};
if($@){
print "Failed ".ref($dom)."::findnodes('$xpath') \$@ $@\n";
}else{
print ref($dom)."::findnodes('$xpath') ".scalar(@propfind)." nodes\n\n";
}
eval {
@propfind = $doc->findnodes($xpath);
};
if($@){
print "Failed ".ref($doc)."::findnodes('$xpath') \$@ $@\n";
}else{
print ref($doc)."::findnodes('$xpath') ".scalar(@propfind)." nodes\n\n";
}
}
# Example in section 9.1.3 of RFC4918
my $txt1 = '
';
# Example in section 9.1.5 of RFC4918
my $txt2 = '
';
my $xpath1 = '/DAV:propfind/DAV:prop';
my $xpath2 = '/DAV:propfind/DAV:propname';
my $xpath3 = '/D:propfind/D:prop';
my $xpath4 = '/D:propfind/D:propname';
my $xpath5 = '/propfind/prop';
my $xpath6 = '/propfind/propname';
print "\$txt1 \$xpath1 \n";
&doitLX(\$txt1, $xpath1);
print "\$txt2 \$xpath2 \n";
&doitLX(\$txt2, $xpath2);
print "\$txt1 \$xpath3 \n";
&doitLX(\$txt1, $xpath3);
print "\$txt2 \$xpath4 \n";
&doitLX(\$txt2, $xpath4);
print "\$txt1 \$xpath5 \n";
&doitLX(\$txt1, $xpath5);
print "\$txt2 \$xpath6 \n";
&doitLX(\$txt2, $xpath6);