in reply to Having trouble with siblings
This extracts all the childnodes into an array. I've printed them out with numbers and delimiter so you can see them individually. I suggest you loop through them extracting all or any that you want.
poj#!perl use strict; use XML::LibXML; my $dom = XML::LibXML->load_xml( IO => *DATA ); my $study_str = 'Purpose and rationale|Study purpose|Study rationale'; for my $search ('//header') { my $nodeset = $dom->find($search); foreach my $node ($nodeset->get_nodelist){ if ($node =~ m/$study_str/i){ my @childnodes = $node->nonBlankChildNodes(); my $n=1; for (@childnodes){ print '#'.$n++.'# '.$_->toString."##\n\n"; } } } } __DATA__ <root> <part><sect> <header> 1. Purpose and rationale doc 1 <p>purpose 1</p> <p>Purpose 2</p> <p>purpose 3</p> <ul> <li>purpose list 1</li> <li>list2</li> </ul> <p>2. Some other heading</p> <p>content 1</p> <p>content 2</p> </header> </sect></part> </root>
|
|---|