This is not a modified Xpath but shows how you can access the child nodes:
use XML::LibXML;
my $string = q|
<Root>
<Parent>
<child1>Child 1</child1>
<child2>Child 2</child2>
<child3>Child 3</child3>
</Parent>
</Root>|;
my $doc = XML::LibXML->load_xml(string => $string);
my @nodes = $doc->findnodes('//Parent');
for my $node (@nodes) {
my @childnodes = $node->childNodes or next;
for my $cnode (@childnodes) {
if ($cnode->nodeName =~ m/^child/) {
print 'name: '. $cnode->nodeName . ', ';
print 'content: '. $cnode->textContent ."\n";
}
}
}
# Output:
# name: child1, content: Child 1
# name: child2, content: Child 2
# name: child3, content: Child 3
See
XML::LibXML::Node