#46307 [Opn->Bgs]: xml_parse / xml_set_character_data_handler doesn't resolve simple entities

From: Date: Thu, 16 Oct 2008 18:07:52 +0000
Subject: #46307 [Opn->Bgs]: xml_parse / xml_set_character_data_handler doesn't resolve simple entities
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-129760@lists.php.net to get a copy of this message
ID: 46307 Updated by: rrichards@php.net Reported By: phpbugs at lange dot nom dot fr -Status: Open +Status: Bogus Bug Type: XML related Operating System: GNU/Linux, Fedora Release 9 PHP Version: 5.2.6 New Comment: Please do not submit the same bug more than once. An existing bug report already describes this very problem. Even if you feel that your issue is somewhat different, the resolution is likely to be the same. Thank you for your interest in PHP. Duplicate of bug #45996 Previous Comments: ------------------------------------------------------------------------ [2008-10-15 19:52:41] phpbugs at lange dot nom dot fr Description: ------------ It may be a misunderstanding of mine, but xml_parse doesn't seem to resolve 'simple' entities like &lt; &gt; or &amp;. According to the doc, and one other bug report, I think it should. While other parsers (XMLReader, SimpleXML, DOM, ...) do. In numerical form, it does work (&#x3e;). I tested with libxml2 versions 2.7.1 and 2.7.2, and expat 2.0.1. I found this when doing SOAP calls, I couldn't pass the value "<" to a PHP SOAP server (which is using NuSOAP). I don't have a workaround for the moment. Reproduce code: --------------- function character_data($parser, $data){ print("character_data: $data\n"); } function parsestring( $strg ) { $parser = xml_parser_create("UTF-8"); xml_set_character_data_handler($parser,'character_data'); xml_parse($parser,$strg,true); xml_parser_free($parser); $reader = new XMLReader(); $reader->XML( $strg ); while( $reader->read() ) { if( $reader->value ) print( $reader->name . ": " . $reader->value . "\n"); } } $xmlcdata = "<element><![CDATA[A>B&C<D]]></element>"; $xmlescaped = "<element>A&gt;B&amp;C&lt;D</element>"; $xmlnumeric = "<element>A&#x3e;B&#x26;C&#x3c;D</element>"; print("parsing $xmlcdata \n"); parsestring( $xmlcdata ); print("\nparsing $xmlescaped \n"); parsestring( $xmlescaped ); print("\nparsing $xmlnumeric \n"); parsestring( $xmlnumeric ); Expected result: ---------------- parsing <element><![CDATA[A>B&C<D]]></element> character_data: A>B&C<D #cdata-section: A>B&C<D parsing <element>A&gt;B&amp;C&lt;D</element> character_data: A character_data: > character_data: B character_data: & character_data: C character_data: < character_data: D #text: A>B&C<D parsing <element>A&#x3e;B&#x26;C&#x3c;D</element> character_data: A character_data: > character_data: B character_data: & character_data: C character_data: < character_data: D #text: A>B&C<D Actual result: -------------- parsing <element><![CDATA[A>B&C<D]]></element> character_data: A>B&C<D #cdata-section: A>B&C<D parsing <element>A&gt;B&amp;C&lt;D</element> character_data: A character_data: B character_data: C character_data: D #text: A>B&C<D parsing <element>A&#x3e;B&#x26;C&#x3c;D</element> character_data: A character_data: > character_data: B character_data: & character_data: C character_data: < character_data: D #text: A>B&C<D ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=46307&edit=1

« previous php.bugs (#129760) next »