PHP DOMNode entities and nodeValue

Posted by Obsidian on Stack Overflow See other posts from Stack Overflow or by Obsidian
Published on 2010-05-02T04:19:04Z Indexed on 2010/05/02 4:27 UTC
Read the original article Hit count: 364

Filed under:
|

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);

© Stack Overflow or respective owner

Related posts about php

Related posts about dom