note 119937 added to function.xmlwriter-write-attribute
| From: | Paul | Date: | Fri, 23 Sep 2016 20:43:27 +0000 |
| Subject: | note 119937 added to function.xmlwriter-write-attribute | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-206657@lists.php.net to get a copy of this message | ||
If you intermix writing sub-elements and attributes, any attempt to write attributes after the first
sub-element will fail and return false:
<?php
$xml = new XMLWriter();
$xml->openMemory();
$xml->startElement('element');
$xml->writeAttribute('attr1', '0');
$xml->writeElement('subelem', '0');
var_dump($xml->writeAttribute('attr2', '0'));
$xml->endElement();
echo $xml->flush();
?>
Outputs:
bool(false)
<element attr1="0"><subelem>0</subelem></element>
This is because this is a forward-only writer and the start tags are already finished. There is no
going back to add more attributes later, there is no place to put attr2. This is exactly how it is
supposed to work.
----
Server IP: 72.52.91.14
Probable Submitter: 69.181.163.176
----
Manual Page -- http://php.net/manual/en/function.xmlwriter-write-attribute.php
Edit -- https://master.php.net/note/edit/119937
Del: integrated -- https://master.php.net/note/delete/119937/integrated
Del: useless -- https://master.php.net/note/delete/119937/useless
Del: bad code -- https://master.php.net/note/delete/119937/bad+code
Del: spam -- https://master.php.net/note/delete/119937/spam
Del: non-english -- https://master.php.net/note/delete/119937/non-english
Del: in docs -- https://master.php.net/note/delete/119937/in+docs
Del: other reasons-- https://master.php.net/note/delete/119937
Reject -- https://master.php.net/note/reject/119937
Search -- https://master.php.net/manage/user-notes.php