开发者

Why is the class DOMText returned for childrens after a DOMNodeList iteration?

$html = 'foo blah <a href="">foo bar</a&开发者_JS百科gt; blah <a href="">foo</a> blah foo';
$dom = new DOMDocument();
$dom->loadHtml($html);

$xpath = new DOMXPath($dom);
$nodes = $xpath->query('//text()');
echo get_class($nodes);
foreach($nodes as $node) {
    echo '<br />';
    echo get_class($node) . ':'; //look here
    echo $node->wholeText;
}

Why is the class type DOMText for each $node ?


Your query is asking for text nodes with //text(). :)

DOMText is a specialized DOMNode, which in its turn is the base object for just about every DOM related object (except DOMXPath, I believe, which makes sense)

The object hierarchy for DOMText is actually as followed;

DomNode  
 - DOMCharacterData
   - DomText

You can learn more about this by examining the docs

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜