title: Is there a way to get simple XML child elements by node name?
body: <p>In PHP, is there an existing method to get one or more child elements by node name (recursively) or would you have to write a function for that yourself? </p>
  
  <p>For example, this is my XML:</p>
  
  <pre><code>&lt;parent&gt;
      &lt;child&gt;
          &lt;grandchild&gt;Jan&lt;/grandchild&gt;
          &lt;grandchild&gt;Kees&lt;/grandchild&gt;
      &lt;/child&gt;
  &lt;/parent&gt;
  </code></pre>
  
  <p>And I'm looking for a method that returns something like:
      Array(
         [0] => 'Jan',
         [1] => 'Kees'
      )</p>
  
  <p>by means of calling something like:</p>
  
  <pre><code>$grandchildren = $xml-&gt;children('grandchild');
  </code></pre>
  
  <p>The above does exist according to documentation but only for namespaces.</p>
  
  <p>e: The accepted answer below worked. This is what I ran to test it.</p>
  
  <pre><code>$xml = '
      &lt;parent&gt;
          &lt;child&gt;
              &lt;grandchild&gt;Jan&lt;/grandchild&gt;
              &lt;grandchild&gt;Kees&lt;/grandchild&gt;
          &lt;/child&gt;
      &lt;/parent&gt;';
  
  $L_o_xml = new SimpleXMLElement($xml);
  
  $L_o_child = $L_o_xml-&gt;xpath('//grandchild');
  
  foreach( $L_o_child as $hi ){
     print "\n".(string)$hi;
  }
  </code></pre>
  
  <p>Simply printed:</p>
  
  <pre><code>Jan
  Kees
  </code></pre>