title: jQuery-like selectors for PHP DOMDocument
body: <p>I'm working with a <a href="http://php.net/manual/en/class.domdocument.php" rel="noreferrer"><code>DOMDocument</code></a>, and I'm wondering if there exists some way of using CSS-like selectors to select nodes like we would in <a href="https://api.jquery.com/category/selectors/" rel="noreferrer">jQuery</a>.</p>
  
  <p>Example situation: I'm parsing an XML file, one snippet of which looks like this:</p>
  
  <pre><code>&lt;gesmes:Envelope&gt;
      &lt;gesmes:subject&gt;Reference rates&lt;/gesmes:subject&gt;
      &lt;gesmes:Sender&gt;
          &lt;gesmes:name&gt;European Central Bank&lt;/gesmes:name&gt;
      &lt;/gesmes:Sender&gt;
      &lt;Cube&gt;
          &lt;Cube time="2009-07-13"&gt;
              &lt;Cube currency="USD" rate="1.3975"/&gt;
              &lt;Cube currency="JPY" rate="129.03"/&gt;
              &lt;Cube currency="BGN" rate="1.9558"/&gt;
              &lt;Cube currency="CZK" rate="26.028"/&gt;
          &lt;/Cube&gt;
      &lt;/Cube&gt;
  &lt;/gesmes:Envelope&gt;
  </code></pre>
  
  <p>Accessing this structure with jQuery-like selectors would be dead simple. For example, I could use</p>
  
  <pre><code>$("Cube[currency]")
  </code></pre>
  
  <p>to retrieve all the <code>Cube</code> elements with the 'currency' attribute.</p>
  
  <p>But how can I do the same thing with PHP's <code>DOMDocument</code>? I'd like to select elements which have an attribute, or have a particular attribute value.</p>