Rwky
Rwky

Reputation: 2144

PHP DOMNode entities and nodeValue

When getting the nodeValue of a DOMNode object that has entities in the nodeValue (i.e. a & gt;) then it converts the entity into it's printable character (i.e. >)

Does anyone know of a way to get it to keep it as an entity, it really messes up string comparisons when it converts to something unexpected.

The following code reproduces the problem you will notice the length of the dump is 3 when it should be 6.

<?php
$xml='<?xml version="1.0"?>
<root>
<element>&gt;</element>
</root>';
$a=new DOMDocument();
$a->loadXML($xml);
var_dump($a->childNodes->item(0)->nodeValue);

Upvotes: 4

Views: 1211

Answers (1)

Michael Mrozek
Michael Mrozek

Reputation: 175665

loadXML() takes an options argument, and one of the options is LIBXML_NOENT, which enables converting entities to their representations, so by default loadXML() shouldn't do so. However, there appears to be a bug in libxml that causes it to happen all the time, according to this bug report

Upvotes: 7

Related Questions