title: PHP: Check if XML node exists with attribute
body: <p>I can't seem to figure this one out.  I have the following XML file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;targets&gt;
    &lt;showcases&gt;
      &lt;building name="Big Blue" /&gt;
      &lt;building name="Shiny Red" /&gt;
      &lt;building name="Mellow Yellow" /&gt;
    &lt;/showcases&gt;
  &lt;/targets&gt;
  </code></pre>
  
  <p>I need to be able to test whether or not a <code><code>&lt;building&gt;</code></code> node exists with a given name.  Everything I seem to find on Google tells me to do something like the following:</p>
  
  <pre><code>$xdoc-&gt;getElementsByTagName('building')-&gt;item(0)-&gt;getAttributeNode('name')
  </code></pre>
  
  <p>... but if I understand that correctly, doesn't that only test the first <code>&lt;building&gt;</code> node?  <code>item(0)</code>? Do I need to use XQuery for this?</p>
  
  <p>I'd appreciate some help! Thanks!</p>