I have a simple xml file that looks like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<microplateDoc xmlns="http://moleculardevices.com/microplateML">
<camelids>
<species name="Camelus bactrianus">
<common-name>Bactrian Camel</common-name>
<physical-characteristics>
<mass>450 to 500 kg.</mass>
<appearance>
Blah blah blah
</appearance>
</physical-characteristics>
</species>
</camelids>
</microplateDoc>
I'm trying to read the species names with the following perl script:
use XML::LibXML;
my $parser = XML::LibXML->new();
my $doc = $parser->parse_file('/Users/johncumbers/Documents/7_Scripts/Perl/XML_to_MySQL/simplified_camelids.xml');
my $xc = XML::LibXML::XPathContext->new( $doc->documentElement() );
$xc->registerNs('ns', 'http://moleculardevices.com/microplateML');
#loop through to find species nodes
my @n = $xc->findnodes('*/species'); #was */species
foreach $nod (@n) {
print "A: ".$nod->getAttribute("name")."\n";
my @c = $nod->findnodes('./common-name');
}
But I am failing to get find any nodes. Are you able to help and tell me why it is not working please? What is the best website to look up perl functions so that I can try and trouble shoot this myself? How can I get the script to tell me what it is doing, as the output at the moment is just nothing. Many thanks.