This example should do the trick. Note that DTD nodes don't appear in the XPath model, so I grep for those first.
use 5.010;
use XML::LibXML 1.70 ':all';
my $dom = XML::LibXML-> load_xml(IO => \*DATA);
my @nodes = (
(grep { $_->nodeType == XML_DTD_NODE } $dom->childNodes),
$dom->findnodes('//node() | //@*'),
);
foreach (@nodes) {
say "Node name: ", $_->nodeName;
say "Node path: ", $_->nodePath;
say "---";
}
__DATA__
<!DOCTYPE foo>
<foo>
<?processing-instruction?>
<!-- a comment -->
<bar attr="1" />
</foo>
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'