请注意,注释的 textContent 属性不会被实体解码,它在 DOMElement::textContent 中被解码
<?php
$xml = new DOMDocument();
$xml->loadXML('<?xml version="1.0" encoding="utf-8"?>
<configuration version="2">
<!-- test --> -->
test -->
</configuration>'
);
$xpath = new DOMXPath($xml);
$comments = $xpath->query('//comment()');
$elements = $xpath->query('//configuration');
echo $comments[0]->textContent;
// 结果: test -->
echo $elements[0]->textContent;
// 结果: test -->
?>