: Request #41326 :: Writing empty tags with Xmlwriter::WriteElement[ns]
| 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
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
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2007-05-08 21:42 UTC] pajoye@php.net
[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.