#41204 [NEW]: DOMDocument::loadXML() fails when entities included in string

From: Date: Thu, 26 Apr 2007 16:42:36 +0000
Subject: #41204 [NEW]: DOMDocument::loadXML() fails when entities included in string
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-111963@lists.php.net to get a copy of this message
From: jazzslider at gmail dot com Operating system: Linux PHP version: 5.2.1 PHP Bug Type: DOM XML related Bug description: DOMDocument::loadXML() fails when entities included in string Description: ------------ When using loadXML() to fill in a DOMDocument object from a pre-existing XML string, entity references will cause the method to fail, even though there does not seem to be a way to explicitly define such entity references in the document prior to calling loadXML(), nor does it seem to be necessary to do so when creating the same document via DOMDocument methods directly. Also note: I am using PHP 5.2.0-8, and cannot upgrade to 5.2.1 since my site is on a shared server. Reproduce code: --------------- <h1>DOMDocument Entity Test</h1> <h2>Created Via DOM Methods</h2> <div> <?php $dd1 = new DOMDocument(); $dd1_root = $dd1->createElement('span', 'This is the sample span.'); $dd1_root = $dd1->appendChild($dd1_root); $dd1_nbsp = $dd1->createEntityReference('nbsp'); $dd1_nbsp = $dd1_root->appendChild($dd1_nbsp); $str = $dd1->saveXML(); echo $str; ?> </div> <h2>Loaded From String</h2> <?php $dd2 = new DOMDocument(); $dd2->loadXML($str); echo $dd2->saveXML(); ?> Expected result: ---------------- The content of the "Created Via DOM Methods" section should be identical to the content of the "Loaded From String" section. Actual result: -------------- With warnings enabled, the following message appears: "Warning: DOMDocument::loadXML() [function.DOMDocument-loadXML]: Entity 'nbsp' not defined in Entity, line: 2 in ..." -- Edit bug report at http://bugs.php.net/?id=41204&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=41204&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=41204&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=41204&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=41204&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=41204&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=41204&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=41204&r=needscript Try newer version: http://bugs.php.net/fix.php?id=41204&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=41204&r=support Expected behavior: http://bugs.php.net/fix.php?id=41204&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=41204&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=41204&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=41204&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=41204&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=41204&r=dst IIS Stability: http://bugs.php.net/fix.php?id=41204&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=41204&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=41204&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=41204&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=41204&r=mysqlcfg

« previous php.bugs (#111963) next »