Finding all empty DOM Nodes
Is it po开发者_如何转开发ssible to identify a DOM node if it is empty using just xPath?
For example, any node like so:
<div></div>
I am hoping to do just a length
on the returned nodes of the xPath like so:
$doc = new DOMDocument();
$doc->loadHTML($html);
$xpath = new DOMXPath($doc);
$xpath_rule = "XPATH";
$returned_nodes = $xpath->query($xpath_rule);
if($returned_nodes->length > 0){ // it is not empty
If this can't be done with xPath, how can I do this efficiently by traversing the whole DOM tree?
Only xPath 1.0 is supported by PHP5.
This XPath expression matches all elements without children or containing only whitespace:
//*[not(*) and not(normalize-space(.))]
精彩评论