in reply to XML::LibXML parentNode only root element

You can use the following-sibling and preceding-sibling axes.
#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; use XML::LibXML; my $dom = 'XML::LibXML'->load_xml(location => shift); my $root = $dom->getDocumentElement(); my ($bfm) = $root->findnodes('//breakfast_menu'); say for $bfm->findnodes('(following-sibling::* | preceding-sibling::*) +');
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]