ID:               41204
 Updated by:       [EMAIL PROTECTED]
 Reported By:      jazzslider at gmail dot com
-Status:           Open
+Status:           Assigned
 Bug Type:         DOM XML related
 Operating System: Linux
 PHP Version:      5.2.1
-Assigned To:      
+Assigned To:      rrichards


Previous Comments:
------------------------------------------------------------------------

[2007-04-27 14:24:54] jazzslider at gmail dot com

Further observation:

The problem is solved partially by adding a custom DTD reference to the
beginning of the string (after the <?xml...?> processing instruction)
containing mainly entity declarations.

When this is done, the only unexpected behavior left is that, if the
XML string contains the &quot; entity, it WILL be substituted...i.e.,
the XML string:

===============================================================
<...PI and DOCTYPE...><span>&quot;Hello!&quot; This &amp; that
are&nbsp;my very favorite things.</span>
===============================================================

will, after loadXML()ing it into a new DOMDocument(), cause saveXML()
to produce the following output:

===============================================================
<...PI and DOCTYPE...><span>"Hello!" This &amp; that are&nbsp;my very
favorite things.</span>
===============================================================

(this is all assuming, of course, that the DOCTYPE declaration includes
all of the entities in the string in keeping with how they are
conventionally understood in HTML)

It is strange that the &quot; entity should be automatically
substituted while none of the others are.  It would make more sense to
me if NONE of the entities were substituted; that's the behavior I'm
looking for.

------------------------------------------------------------------------

[2007-04-26 16:42:35] jazzslider at gmail dot com

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 this bug report at http://bugs.php.net/?id=41204&edit=1

Reply via email to