I\'m working with a DOMDocument, and I\'m wondering if there exists some way of using CSS-like selectors to select nodes like we would in jQuery.
Example situation: I\'m
Take a look at the DOMXPath class in PHP. It uses XPath, so you'll need to read up on XPath syntax if you're unfamiliar with it. There's some documentation on MSDN, or you can read the W3 spec if you're particularly brave.
To solve your example problem: //cube[@currency]
is an XPath query that selects all elements in the document with a currency attribute. Usage of this with the DOMXPath
class would look like this:
$xpath = new DOMXpath($myDomDocument);
$cubesWithCurrencies = $xpath->query('//cube[@currency]');
$cubesWithCurrencies
is now a DOMNodeList that you can iterate over.