Note that textContent property of a comment is not entity decoded, it is decoded in 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;// result: test -->echo $elements[0]->textContent;// result: test -->?>