NCBI xml-format Printing nodeValues from tags with the same names 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

&lt;Gene-commentary_heading&gt;GeneOntology&lt;/Gene-commentary_heading&gt;
      &lt;Gene-commentary_source&gt;
        &lt;Other-source&gt;
          &lt;Other-source_pre-text&gt;Provided by&lt;/Other-source_pre-text&gt;
          &lt;Other-source_anchor&gt;GOA&lt;/Other-source_anchor&gt;
          &lt;Other-source_url&gt;http://www.ebi.ac.uk/GOA/&lt;/Other-source_url&gt;
        &lt;/Other-source&gt;
      &lt;/Gene-commentary_source&gt;
      &lt;Gene-commentary_comment&gt;
        &lt;Gene-commentary&gt;
          &lt;Gene-commentary_type value="comment"&gt;254&lt;/Gene-commentary_type&gt;
          &lt;Gene-commentary_label&gt;Function&lt;/Gene-commentary_label&gt;
          &lt;Gene-commentary_comment&gt;
            &lt;Gene-commentary&gt;
              &lt;Gene-commentary_type value="comment"&gt;254&lt;/Gene-commentary_type&gt;
              &lt;Gene-commentary_source&gt;
                &lt;Other-source&gt;
                  &lt;Other-source_src&gt;
                    &lt;Dbtag&gt;
                      &lt;Dbtag_db&gt;GO&lt;/Dbtag_db&gt;
                      &lt;Dbtag_tag&gt;
                        &lt;Object-id&gt;
                          &lt;Object-id_id&gt;3677&lt;/Object-id_id&gt;
                        &lt;/Object-id&gt;
                      &lt;/Dbtag_tag&gt;
                    &lt;/Dbtag&gt;
                  &lt;/Other-source_src&gt;
                  &lt;Other-source_anchor&gt;DNA binding&lt;/Other-source_anchor&gt;


code:

$esearch_test = "https://www.ncbi.nlm.nih.gov/gene/7128?report=xml&amp;format=text";
$result = file_get_contents($esearch_test);
$xml = simplexml_load_string($result);
$doc = new DOMDocument();
$doc = DOMDocument::loadXML($xml);
$c = 1;
foreach($doc-&gt;getElementsByTagName('Gene-commentary_heading') as $node) {
    if ($node-&gt;textContent =="GeneOntology"){
        echo "&lt;pre&gt;"."$c: ".$node-&gt;nodeName."&lt;/pre&gt;";
        echo "&lt;pre&gt;"."$c: ".$node-&gt;nodeValue."&lt;/pre&gt;";
        $cn = 1;
        foreach ($node-&gt;getElementsByTagName('Other-source_anchor') as $subnode){
            echo "&lt;pre&gt;"."$c: ".$subnode-&gt;nodeName."&lt;/pre&gt;";
            echo "&lt;pre&gt;"."$c: ".$subnode-&gt;nodeValue."&lt;/pre&gt;"; 

            echo $cn++;
        }
    }
    $c++;
}
use a XSLT processor (http://php.net/manual/en/class.xsltprocessor.php) with the following stylesheet.

&lt;?xml version='1.0' encoding="UTF-8"?&gt;
&lt;xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'&gt;
    &lt;xsl:output method="html"/&gt;

    &lt;xsl:template match="/"&gt;
        &lt;div&gt;
            &lt;xsl:apply-templates select="//Gene-commentary_heading[ text() = 'GeneOntology']"/&gt;
        &lt;/div&gt;
    &lt;/xsl:template&gt;

    &lt;xsl:template match="Gene-commentary_heading"&gt;
        &lt;pre&gt;&lt;xsl:value-of select="name(.)"/&gt;&lt;/pre&gt;
        &lt;pre&gt;&lt;xsl:value-of select="."/&gt;&lt;/pre&gt;
        &lt;xsl:apply-templates select="..//Other-source_anchor"/&gt;
    &lt;/xsl:template&gt;

    &lt;xsl:template match="Other-source_anchor"&gt;
        &lt;pre&gt;&lt;xsl:value-of select="name(.)"/&gt;&lt;/pre&gt;
        &lt;pre&gt;&lt;xsl:value-of select="."/&gt;&lt;/pre&gt;
    &lt;/xsl:template&gt;

&lt;/xsl:stylesheet&gt;