Although I'm definitely not an expert in the latter, there does seem to be a difference between XML::LibXML and XML::XSH2.
<update> I think I found it, looks like it's the option load_ext_dtd=>0, from XML::LibXML::Parser: "Thus switching off external DTD loading, will disable entity expansion, validation, and complete attributes on internal subsets as well." </update>
#!/usr/bin/env perl
use warnings;
use strict;
our $XML = <<'_END_XML_';
<!DOCTYPE html [ <!ENTITY atad "data"> ] >
<html xmlns="http://www.w3.org/1999/xhtml">
<div class="data" id="One" />
<div class="&atad;" id="Two" />
<div class="&atad;" id="Three" />
</html>
_END_XML_
use XML::LibXML ();
print $XML::LibXML::VERSION, " ",
XML::LibXML::LIBXML_DOTTED_VERSION, " ",
XML::LibXML::LIBXML_VERSION, " ",
XML::LibXML::LIBXML_RUNTIME_VERSION, "\n";
my $dom = XML::LibXML->load_xml(string=>$XML);
my $xpc = XML::LibXML::XPathContext->new($dom);
$xpc->registerNs(xh => 'http://www.w3.org/1999/xhtml');
for my $div ($xpc->findnodes('//xh:div[@class="data"]')) {
print "1:", $div->{id}, "\n"
}
for my $div ($xpc->findnodes('//xh:div')) {
print "2:", $div->{id}, " ", $div->{class}, "\n"
}
use XML::XSH2 'xsh';
print $XML::XSH2::VERSION, "\n";
xsh(<<'_END_XSH_');
open :s {$::XML} ;
register-namespace xh http://www.w3.org/1999/xhtml ;
for //xh:div[@class="data"] {
echo "a:" @id ;
}
for //xh:div {
echo "b:" @id @class ;
}
_END_XSH_
__END__
2.0130 2.9.1 20901 20901
1:One
1:Two
1:Three
2:One data
2:Two data
2:Three data
2.1.26
parsing string
done.
a: One
b: One data
b: Two data
b: Three data
|