php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41634 DOM XML tags with empty value generate different xml than tags with no value
Submitted: 2007-06-08 14:20 UTC Modified: 2007-06-08 15:28 UTC
From: evan dot kaufman at gmail dot com Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.2.3 OS: Mac OS X
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: evan dot kaufman at gmail dot com
New email:
PHP Version: OS:

 

 [2007-06-08 14:20 UTC] evan dot kaufman at gmail dot com
Description:
------------
When a tag created with DOMDocument->createElement() is given *no* value, its generated output (using DOMDocument->saveXML()) is a shortened (self-closing) tag, but when it is given an *empty* value such as a blank string or NULL, it displays as an expanded (opening and closing) tag.

Shouldn't any empty value be treated the same?  If anyone really wanted expanded tags, they could use the already implemented LIBXML_NOEMPTYTAG option, but there is no equivalent option to ask for shortened tags.

Reproduce code:
---------------
$doc1 = new DOMDocument();
$root1 = $doc1->createElement('root');
$doc1->appendChild($root1);
printf( "doc1: %s\n", $doc1->saveXML() );

$doc2 = new DOMDocument();
$root2 = $doc2->createElement('root', '');
$doc2->appendChild($root2);
printf( "doc2: %s\n", $doc2->saveXML() );

$doc3 = new DOMDocument();
$root3 = $doc3->createElement('root', NULL);
$doc3->appendChild($root3);
printf( "doc3: %s\n", $doc3->saveXML() );

Expected result:
----------------
doc1: <?xml version="1.0"?><root/>
doc2: <?xml version="1.0"?><root/>
doc3: <?xml version="1.0"?><root/>

Actual result:
--------------
doc1: <?xml version="1.0"?><root/>
doc2: <?xml version="1.0"?><root></root>
doc3: <?xml version="1.0"?><root></root>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-06-08 15:28 UTC] rrichards@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

createElement, by the spec, only accepts 1 argument and creates an element node (no content - behavior you see not passing in argument). When you pass in the second arg (which the binding allows by expanding upon the spec, you are thereby asking for text node to be created within the element and and thus if empty produces open and close tag.

If you don't want that then don't pass 2nd (optional) arg.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 22:01:28 2024 UTC