in reply to problems with Xpath
this module is not available in ppm
Are you certain you have XML::XPath installed?
HTH,
planetscape
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: problems with Xpath
by Anonymous Monk on Jan 10, 2008 at 17:16 UTC | |
#!/usr/bin/perl
use strict;
use XML::XPath;
use XML::XPath::XMLParser;
use XML::XPath::Node::Element;
use XML::XPath::NodeSet;
my $file = "nci.xml";
my $xp = XML::XPath-> new(filename => $file);
open(info,"+>$file.txt");
foreach my $concept ($xp->findnodes('/NCI_PID_XML/Ontology/LabelType')) {
my $parentid = $concept->getAttribute('id');
my $type = $concept->getAttribute('name');
my $LabelValue = $concept->findnodes('LabelValueList');
my $id = $LabelValue->getAttribute('id');
my $name = $LabelValue->getAttribute('name');
my $goid = $LabelValue->getAttribute('GO');
print info "$parentid\t";
print info "$type\t";
print info "id\t";
print info "name\t";
print info "$goid\n";
}
but it is giving me error Can't locate object method "getAttribute" via package "XML::XPath::NodeSet" at try1.pl line 15. any any one suggest me a solution Thanks | [reply] |
by planetscape (Chancellor) on Jan 10, 2008 at 17:42 UTC | |
When I run your code, I do NOT get any errors (warnings, yes). But then, I have XML::XPath installed. I suggest installing modules before attempting to use them. Update: Note that I'm not saying the code does what you want; see other replies in this thread for that. But to get the Can't locate object method "getAttribute" via package "XML::XPath::NodeSet" at C:\Perl\try1.pl line 13. error to go away, install the module. HTH, planetscape | [reply] [d/l] |
by ikegami (Patriarch) on Jan 10, 2008 at 18:05 UTC | |
NetWallah's right in saying the OP is incorrectly treating an XML::XPath::NodeSet object as an XML::XPath::Node::Element object. The OP should review the return value of findnodes. | [reply] [d/l] [select] |
by olus (Curate) on Jan 10, 2008 at 17:26 UTC | |
On the XML I had to add the nodes <NCI_PID_XML> and <Ontology> Also changed your code to cycle through the LabelValue nodes and call getAttribute on them. Also closed the file at the end and corrected typos for $id and $name. And on the nci.txt file I now have
| [reply] [d/l] [select] |
by Anonymous Monk on Jan 10, 2008 at 17:21 UTC | |
<LabelType name="function" id="8">
<LabelValueList>
<LabelValue name="acyltransferase activity" id="8007" parent_idref="8000" GO="GO:0008415" />
<LabelValue name="calcium- and calmodulin-responsive adenylate cyclase activity" id="8008" parent_idref="8000" GO="GO:0008294" />
<LabelValue name="casein kinase I activity" id="11900" parent_idref="8000" GO="GO:0004681" />
<LabelValue name="casein kinase activity" id="9634" parent_idref="8000" GO="GO:0004680" />
<LabelValue name="function" id="75" parent_idref="75" />
<LabelValue name="guanylate cyclase activity" id="8009" parent_idref="8000" GO="GO:0004383" />
<LabelValue name="interleukin-12 receptor activity" id="8015" parent_idref="8000" GO="GO:0016517" />
<LabelValue name="metalloendopeptidase activity" id="8010" parent_idref="8000" GO="GO:0004222" />
<LabelValue name="molecular_function" id="8000" parent_idref="75" GO="GO:0003674" />
<LabelValue name="potassium channel inhibitor activity" id="10264" parent_idref="8000" GO="GO:0019870" />
<LabelValue name="protein serine/threonine phosphatase activity" id="8002" parent_idref="8000" GO="GO:0004722" />
<LabelValue name="protein tyrosine phosphatase activity" id="8013" parent_idref="8000" GO="GO:0004725" />
<LabelValue name="retinol isomerase activity" id="8012" parent_idref="8000" GO="GO:0050251" />
<LabelValue name="serine protease" id="8003" parent_idref="8000" />
<LabelValue name="specific transcriptional repressor activity" id="8019" parent_idref="8000" GO="GO:0016566" />
<LabelValue name="telomeric DNA binding" id="8005" parent_idref="8000" GO="GO:0042162" />
<LabelValue name="transcription factor activity" id="8018" parent_idref="8000" GO="GO:0003700" />
<LabelValue name="transcription repressor activity" id="8017" parent_idref="8000" GO="GO:0016564" />
<LabelValue name="tumor necrosis factor receptor activity" id="8004" parent_idref="8000" GO="GO:0005031" />
</LabelValueList>
</LabelType>
this is how the XML file isThanks | [reply] |