Bug #74494 [Nab]: DOMDocument::saveXML() LIBXML_NOEMPTYTAG option is ignored
Edit report at https://bugs.php.net/bug.php?id=74494&edit=1
ID: 74494
User updated by: mfburdett at gmail dot com
Reported by: mfburdett at gmail dot com
Summary: DOMDocument::saveXML() LIBXML_NOEMPTYTAG option is
ignored
Status: Not a bug
Type: Bug
Package: DOM XML related
Operating System: FreeBSD
PHP Version: 7.1.4
Block user comment: N
Private report: N
New Comment:
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/>
Previous Comments:
------------------------------------------------------------------------
[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)