I would like to retrieve all Other-source_anchor on the level of DNA binding from within a Gene Ontology XML file using php.
If I try this with my code, I only get Gene Ontology back and not the nodeValues in Other-source_anchor. Could someone tell me how to do this?
Xml file were I wwant to get the nodeValues from
<Gene-commentary_heading>GeneOntology</Gene-commentary_heading>
<Gene-commentary_source>
<Other-source>
<Other-source_pre-text>Provided by</Other-source_pre-text>
<Other-source_anchor>GOA</Other-source_anchor>
<Other-source_url>http://www.ebi.ac.uk/GOA/</Other-source_url>
</Other-source>
</Gene-commentary_source>
<Gene-commentary_comment>
<Gene-commentary>
<Gene-commentary_type value="comment">254</Gene-commentary_type>
<Gene-commentary_label>Function</Gene-commentary_label>
<Gene-commentary_comment>
<Gene-commentary>
<Gene-commentary_type value="comment">254</Gene-commentary_type>
<Gene-commentary_source>
<Other-source>
<Other-source_src>
<Dbtag>
<Dbtag_db>GO</Dbtag_db>
<Dbtag_tag>
<Object-id>
<Object-id_id>3677</Object-id_id>
</Object-id>
</Dbtag_tag>
</Dbtag>
</Other-source_src>
<Other-source_anchor>DNA binding</Other-source_anchor>
code:
$esearch_test = "https://www.ncbi.nlm.nih.gov/gene/7128?report=xml&format=text";
$result = file_get_contents($esearch_test);
$xml = simplexml_load_string($result);
$doc = new DOMDocument();
$doc = DOMDocument::loadXML($xml);
$c = 1;
foreach($doc->getElementsByTagName('Gene-commentary_heading') as $node) {
if ($node->textContent =="GeneOntology"){
echo "<pre>"."$c: ".$node->nodeName."</pre>";
echo "<pre>"."$c: ".$node->nodeValue."</pre>";
$cn = 1;
foreach ($node->getElementsByTagName('Other-source_anchor') as $subnode){
echo "<pre>"."$c: ".$subnode->nodeName."</pre>";
echo "<pre>"."$c: ".$subnode->nodeValue."</pre>";
echo $cn++;
}
}
$c++;
}