Bug #74494 [Nab->Opn]: DOMDocument::saveXML() LIBXML_NOEMPTYTAG option is ignored
Edit report at https://bugs.php.net/bug.php?id=74494&edit=1
ID: 74494
Updated by: requinix@php.net
Reported by: mfburdett at gmail dot com
Summary: DOMDocument::saveXML() LIBXML_NOEMPTYTAG option is
ignored
-Status: Not a bug
+Status: Open
Type: Bug
Package: DOM XML related
Operating System: FreeBSD
PHP Version: 7.1.4
Block user comment: N
Private report: N
New Comment:
I haven't found anything to suggest why yours is working differently. I'm still pretty
sure this is not a bug with PHP but I don't know enough to tell you what to test next (besides
maybe a build straight from the libxml2 sources without FreeBSD's patches?) so I'll move
this back to Open.
Previous Comments:
------------------------------------------------------------------------
[2017-04-25 19:02:42] mfburdett at gmail dot com
phpinfo reports libxml 2.9.4
------------------------------------------------------------------------
[2017-04-25 07:25:32] requinix@php.net
Looks fine to me. https://3v4l.org/pOKD9
What libxml do you have?
------------------------------------------------------------------------
[2017-04-25 00:03:53] mfburdett at gmail dot com
I can also reproduce this bug with an XML document:
<?php
$dom = new \DOMDocument();
$dom->loadXML('<root><node/></root>');
$node = $dom->getElementsByTagName('node')->item(0);
echo $dom->saveXML($node, LIBXML_NOEMPTYTAG);
Expected result: <node></node>
Actual result: <node/>
------------------------------------------------------------------------
[2017-04-24 19:05:19] requinix@php.net
LIBXML_NOEMPTYTAG only applies to XML documents. Yours is HTML.
Use ->saveHTML().
------------------------------------------------------------------------
[2017-04-24 18:11:06] mfburdett at gmail dot com
Description:
------------
When executing a PHP script using the Apache module, the DOMDocument::saveXML() LIBXML_NOEMPTYTAG
option is ignored - a self-closing tag, e.g. <body /> is created.
When executing the same script on the commandline, the LIBXML_NOEMPTYTAG option is honored.
This could be a bug in how PHP, Apache and LibXML are compiled by FreeBSD ports, rather than a bug
in PHP itself.
Test script:
---------------
<?php
$dom = new \DOMDocument();
$dom->loadHTML('<body></body>');
$node = $dom->getElementsByTagName('body')->item(0);
echo $dom->saveXML($node, LIBXML_NOEMPTYTAG);
Expected result:
----------------
<body></body>
Actual result:
--------------
<body/>
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=74494&edit=1
Thread (8 messages)