in reply to LibXML findnode and parents
If the format varies then you need to show that.my @vol = $doc->findnodes('//Volume[@VolumeCategory="6444"]'); for my $element (@vol) { my $parent = $element->parentNode; if ( $parent->nodeName eq 'Job' ) { $parent = $parent->parentNode; } print $parent, "\n"; print $element->textContent(), "\n"; }
Note that you need to use ->textContent and not ->nodeValue to get the text value of the element.
Output:
<Test size="50"> <Job tags="boo baa"> <Volume VolumeCategory="L" MeasurementCategory="Real">0.063</V +olume> <Volume VolumeCategory="cuft" MeasurementCategory="Real">2.2</ +Volume> <Volume VolumeCategory="6444" MeasurementCategory="Deal">2.2</ +Volume> </Job> </Test> 2.2 <Test size="100"> <Volume VolumeCategory="L" MeasurementCategory="Real">0.063</Volum +e> <Volume VolumeCategory="L" MeasurementCategory="Real">0.063</Volum +e> <Volume VolumeCategory="6444" MeasurementCategory="Real">2.2</Volu +me> </Test> 2.2
|
|---|