Edit report at https://bugs.php.net/bug.php?id=64899&edit=1
ID: 64899
User updated by: douglas dot wright at pre-school dot org dot uk
Reported by: douglas dot wright at pre-school dot org dot uk
Summary: Elements with values of empty string are turned into
void elements
Status: Not a bug
Type: Bug
Package: DOM XML related
Operating System: Windows 7
PHP Version: 5.5.0RC1
Block user comment: N
Private report: N
New Comment:
Hi
The workaround of inserting an empty text node manually after element creation
still seems to work, but inserting a text node is what the $value param in
createElement($name,$value) is surely for?
i.e.
$script = $doc->createElement ('script', '') //not working in 5.5
is the same thing as:
$script = $doc->createElement ('script');
$script->appendChild ($doc->createTextNode ('')); //does work in 5.5
On setting, this creates a Text node with the unparsed contents of the string
Previous Comments:
------------------------------------------------------------------------
[2013-05-22 15:06:47] [email protected]
The behaviour you describe is pretty valid for XML. saveHTML() method should be
used if you need a HTML conform output. Also the behavior is different in 5.4
when using loadXML (tested with your snippet). PHP 5.5 uses libxml 2.9.1 where
5.4
uses libxml 2.7.8. libxml supports HTML 4.0 parser only AFAIR (yet at least).
You might be also interested in workarounds suggested by users
http://de2.php.net/manual/en/domdocument.savehtml.php
------------------------------------------------------------------------
[2013-05-22 11:41:55] douglas dot wright at pre-school dot org dot uk
Description:
------------
There is a regression in PHP5.5RC where empty text nodes seem to be lost e.g.
<script src=""></script> is turned into <script src=""/>
This breaks XHTML pages because browsers don't recognise the self-closing
syntax.
In PHP 5.3 and 5.4 the two calls below had different output
$doc->createElement('script') output <script/>
$doc->createElement('script', '') output <script></script>
In PHP5.5, they both output <script/> only. Documents parsed using loadXML
suffer this too - <script></script> loses the inner text node and is
transformed into <script/>.
Test script:
---------------
<?php
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
$doc = new DOMDocument;
$script = $doc->createElement('script', '');
$script->setAttribute('src', 'foo.js');
$doc->appendChild($script);
echo $doc->saveXML();
$doc->loadXML('<script src="abc.js"></script>');
echo $doc->saveXML();
Expected result:
----------------
<?xml version="1.0"?>
<script src="foo.js"></script>
<?xml version="1.0"?>
<script src="foo.js"></script>
Actual result:
--------------
<?xml version="1.0"?>
<script src="foo.js"/>
<?xml version="1.0"?>
<script src="foo.js"/>
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=64899&edit=1