in reply to Getting the value from XML file
<root> <predicted_properties> <property> <kind>water_solubility</kind> <value>0.00169 mg/mL at 25 C</value> <source/> </property> </predicted_properties> <predicted_properties> <property> <kind>formal_charge</kind> <value>-1</value> <source>ChemAxon</source> </property> </predicted_properties> </root>
The code looks for the 'kind' node and then for its sibling node called 'value'
use XML::Twig::XPath; my $twig= XML::Twig::XPath->new(); $twig->parsefile('myfile.xml'); print $twig->findvalue ('/root/predicted_properties/property/kind[text()="formal_charge"]/ following-sibling::value');
prints -1
One suggestion to simplify your xml structure would be to add it as an attribute to kind. ie :
<kind name='formal_charge'>-1</kind>
|
|---|