Try "//comment()"
to get all CommentNodes.
Note that the link element in the CommentNode is not a childNode of the commentNode but mere data:
libxml_use_internal_errors(TRUE);
$dom = new DOMDocument;
$dom->loadHTMLFile( 'http://www.nytimes.com/' );
libxml_clear_errors();
$xpath = new DOMXPath($dom);
foreach( $xpath->query('//comment()[contains(., "link")]') as $node)
{
var_dump( $node->data );
}
This will give:
string(135) "[if IE]>
<link rel="stylesheet" type="text/css" href="http://graphics8.nytimes.com/css/0.1/screen/build/homepage/ie.css">
<![endif]"
string(138) "[if IE 6]>
<link rel="stylesheet" type="text/css" href="http://graphics8.nytimes.com/css/0.1/screen/build/homepage/ie6.css">
<![endif]"
As you can see, the actual comment node is just the <!--
and -->
parts. The remainder is just text. The [if IE]>
is not part of the actual tag. It is character data.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…