Why can't I access elements inside an XML file with XPath in XML::LibXML?
Posted
by John
on Stack Overflow
See other posts from Stack Overflow
or by John
Published on 2010-01-17T01:41:06Z
Indexed on
2010/03/24
12:23 UTC
Read the original article
Hit count: 341
I have an XML file, part of which looks like this:
<wave waveID="1">
<well wellID="1" wellName="A1">
<oneDataSet>
<rawData>0.1123975676</rawData>
</oneDataSet>
</well>
... more wellID's and rawData continues here...
I am trying to parse the file with Perl's libXML and output the wellName and the rawData using the following:
use XML::LibXML;
my $parser = XML::LibXML->new();
my $doc = $parser->parse_file('/Users/johncumbers/Temp/1_12-18-09-111823.orig.xml');
my $xc = XML::LibXML::XPathContext->new( $doc->documentElement() );
$xc->registerNs('ns', 'http://moleculardevices.com/microplateML');
my @n = $xc->findnodes('//ns:wave[@waveID="1"]'); #xc is xpathContent
# should find a tree from the node representing everything beneath the waveID 1
foreach $nod (@n) {
my @c = $nod->findnodes('//rawData'); #element inside the tree.
print @c;
}
It is not printing out anything right now and I think I have a problem with my Xpath statements. Please can you help me fix it, or can you show me how to trouble shoot the xpath statements? Thanks.
© Stack Overflow or respective owner