Bug #64899 [Opn->Nab]: Elements with values of empty string are turned into void elements
| From: | ab@php.net | Date: | Wed, 22 May 2013 15:06:47 +0000 |
| Subject: | Bug #64899 [Opn->Nab]: Elements with values of empty string are turned into void elements | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-179077@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=64899&edit=1
ID: 64899
Updated by: ab@php.net
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: Open
+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:
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
Previous Comments:
------------------------------------------------------------------------
[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