##
`--
`+- a
+-
| `+- b
| +-
| `- c
`- d
##
##
`+-
| `+- a
| `-
| `-- b
`-
`+-
| `-- c
`- d
##
##
use warnings;
use strict;
use XML::LibXML;
my $dom = XML::LibXML->load_xml(string => <<'END_XML');
Foo
B a
r
END_XML
my $xpc = XML::LibXML::XPathContext->new($dom);
$xpc->registerNs('office',
'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
$xpc->registerNs('text',
'urn:oasis:names:tc:opendocument:xmlns:text:1.0');
while (1) {
my ($lb) = $xpc->findnodes('//text:p//text:line-break') or last;
die "can't handle with children: $lb"
if $lb->hasChildNodes;
my ($p) = $xpc->findnodes('ancestor::text:p[1]',$lb)
or die "failed to find ancestor of $lb";
print "$p\n"; #DB
# ... do something useful here ...
$lb->unbindNode; # so this loop terminates
}
print "#####\n";
print $dom;