|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #41326 Writing empty tags with Xmlwriter::WriteElement[ns]
Submitted: 2007-05-08 15:31 UTC Modified: 2007-05-14 09:26 UTC
From: php-bugs-0705 at nico dot edtinger dot at Assigned: pajoye (profile)
Status: Closed Package: Feature/Change Request
PHP Version: 5CVS-2007-05-08 (snap) OS: irrelevant
Private report: No CVE-ID: None
 [2007-05-08 15:31 UTC] php-bugs-0705 at nico dot edtinger dot at
Currently Xmlwriter::WriteElement() and Xmlwriter::WriteElementNS() require the forth argument $content and are therefor not able to output empty tags. Someone has to use XmlWriter::startElement(); and XmlWriter::endElement(); to output an empty tag. That's a bit cumbersome.

It would be nice if $content could be made optional or set to null to output an empty tag. I know it's the documented behavior, that it always write a a full element tag and libxml2 does have the same behavior. Nevertheless it would be a nice addition to be able to write less code for a short tag.

Reproduce code:
$xml = new XmlWriter();
$xml->writeElement('foo', null);
echo $xml->outputMemory();

Expected result:
<?xml version="1.0"?>

Actual result:
<?xml version="1.0"?>


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-05-08 21:42 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

 [2007-05-14 09:26 UTC]
Little notice about the final fix, there is now three cases:

$xml->writeElement('foo', '');

$xml->writeElement('foo', null);


Doing it this way preserves BC while allowing the short form.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 15 13:01:32 2024 UTC