tags:

views:

181

answers:

1

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);
+1  A: 

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

Michael Mrozek
Thanks for that, shame it's a bug, looks like I'll have to run my comparisons through htmlentities.
Obsidian
Huh. Not every day I have an accepted answer at -2. A comment about why it's wrong would be helpful, particular if it turns out there's an easy fix for Obsidian's problem
Michael Mrozek