XPath query to get HTML nodes with multiple classes, using PHP/Zend_Dom_Query?
It's very easy to get an HTML node using Zend_Dom_Query by class:
$dom = new Zend_Dom_Query($html);
$rows = $dom->query("//div[@class='upc']");
However, HTML nodes often have more than one class, e.g.:
<div class="hidden upc">
How is it possible, using Zend_Dom_Query and XPath, to find all nodes which include a particular class in its list of classes, rather than having a specific value for the class attribute?
I have found an example that does this using Java, but app开发者_如何学JAVAlying it to the PHP Xpath engine doesn't seem to work as it gives an error that the XPath query is not valid:
//div[contains(concat(' ',normalize-space(@class),' '),' foo ')]
I think you are looking for this to select the div with multiple classes:
$rows = $dom->query('div.hidden.upc');
精彩评论