<p>I have an XML file loaded into a DOM document, 
I wish to iterate through all 'foo' tags, getting values from every tag below it. I know I can get values via </p>

<pre><code>$element = $dom-&gt;getElementsByTagName('foo')-&gt;item(0);
foreach($element-&gt;childNodes as $node){
    $data[$node-&gt;nodeName] = $node-&gt;nodeValue;
}
</code></pre>

<p>However, what I'm trying to do, is from an XML like, </p>

<pre><code>&lt;stuff&gt;
  &lt;foo&gt;
    &lt;bar&gt;&lt;/bar&gt;
      &lt;value/&gt;
    &lt;pub&gt;&lt;/pub&gt;
  &lt;/foo&gt;
  &lt;foo&gt;
    &lt;bar&gt;&lt;/bar&gt;
    &lt;pub&gt;&lt;/pub&gt;
  &lt;/foo&gt;
  &lt;foo&gt;
    &lt;bar&gt;&lt;/bar&gt;
    &lt;pub&gt;&lt;/pub&gt;
  &lt;/foo&gt;
  &lt;/stuff&gt;
</code></pre>

<p>iterate over every <em>foo</em> tag, and get specific <em>bar</em> or <em>pub</em>, and get values from there.
Now, how do I iterate over <em>foo</em> so that I can still access specific child nodes by name?</p>

Not tested, but what about:
```
```
$elements = $dom->getElementsByTagName('foo');
$data = array();
foreach($elements as $node){
    foreach($node->childNodes as $child) {
        $data[] = array($child->nodeName => $child->nodeValue);
    }
}
```
```