php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: php-bugs-0705 at nico dot edtinger dot at
New email:
PHP Version: OS:

 

 [2007-05-08 15:31 UTC] php-bugs-0705 at nico dot edtinger dot at
Description:
------------
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:
---------------
<?php
$xml = new XmlWriter();
$xml->openMemory();
$xml->startDocument();
$xml->startElement('test');
$xml->writeElement('foo', null);
$xml->startElement('bar');
$xml->endElement('bar');
$xml->endElement();
echo $xml->outputMemory();
?>

Expected result:
----------------
<?xml version="1.0"?>
<test><foo/><bar/></test>

Actual result:
--------------
<?xml version="1.0"?>
<test><foo></foo><bar/></test>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-05-08 21:42 UTC] pajoye@php.net
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
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


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

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

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

$xml->writeElement('foo');
<foo/>

Doing it this way preserves BC while allowing the short form.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Sep 25 10:03:37 2021 UTC