請注意,註釋的 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 -->
?>