|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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>
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 07:00:01 2025 UTC |
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.