text: user2736: 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++;
  } 
  
  
  user71: use a XSLT processor (http://php.net/manual/en/class.xsltprocessor.php) with the following stylesheet.
  <?xml version='1.0' encoding="UTF-8"?>
  <xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>
      <xsl:output method="html"/>
  
      <xsl:template match="/">
          <div>
              <xsl:apply-templates select="//Gene-commentary_heading[ text() = 'GeneOntology']"/>
          </div>
      </xsl:template>
  
      <xsl:template match="Gene-commentary_heading">
          <pre><xsl:value-of select="name(.)"/></pre>
          <pre><xsl:value-of select="."/></pre>
          <xsl:apply-templates select="..//Other-source_anchor"/>
      </xsl:template>
  
      <xsl:template match="Other-source_anchor">
          <pre><xsl:value-of select="name(.)"/></pre>
          <pre><xsl:value-of select="."/></pre>
      </xsl:template>
  
  </xsl:stylesheet>
  
  
original_text: 2736: <p>I would like to retrieve all Other-source_anchor on the level of DNA binding from within a Gene Ontology XML file using php. </p>
  
  <p>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? </p>
  
  <h1>Xml file were I wwant to get the nodeValues from</h1>
  
  <pre class="lang-xml prettyprint-override"><code>&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></pre>
  
  <h1>code:</h1>
  
  <pre class="lang-php prettyprint-override"><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++;
  } 
  </code></pre>
   71: <p>use a XSLT processor (<a href="http://php.net/manual/en/class.xsltprocessor.php" rel="nofollow noreferrer">http://php.net/manual/en/class.xsltprocessor.php</a>) with the following stylesheet.</p>
  
  <pre class="lang-xslt prettyprint-override"><code>&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;
  </code></pre>
  