Bug->Req #68756 [Opn]: Warn, when attributes added after subelements are ignored
Edit report at https://bugs.php.net/bug.php?id=68756&edit=1
ID: 68756
Updated by: cmb@php.net
Reported by: bas5winkel at gmail dot com
-Summary: attributes added after subelements are ignored
+Summary: Warn, when attributes added after subelements are
ignored
Status: Open
-Type: Bug
+Type: Feature/Change Request
-Package: Documentation problem
+Package: XML Writer
-Operating System: all?
+Operating System: *
PHP Version: 5.5.20
Block user comment: N
Private report: N
New Comment:
> Changing to a doc bug as I don't see this caveat mentioned
> anywhere.
The introduction[1] already explains (emphasis mine):
| This extension represents a writer that provides a *non-cached*,
| *forward-only* means of generating streams or files containing
| XML data.
Anyhow, adding respective notes to each function's manual page
appears to be excessive. Consider, for instance, what would happen
when one calls ::startElement() directly after ::startComment().
> Would it be possible to thrown an exception when one tries write
> an attribute after a sub-element is written?
Well, an exception wouldn't fit with the procedural style (PHP
functions don't throw exceptions, yet), and would be quite
invasive wrt. BC anyway. A notice or a warning seem to be more
appropriate, if a call fails. Cf. <https://3v4l.org/9hpYR#v560>;
checking the return value of every call would really be tiresome.
[1] <http://php.net/manual/en/intro.xmlwriter.php>
Previous Comments:
------------------------------------------------------------------------
[2015-01-06 14:45:42] bas5winkel at gmail dot com
Thanks for the quick reply.
Would it be possible to thrown an exception when one tries write an attribute
after a sub-element is written?
This would make it more obvious that one does something that is not possible.
It took me quite a while to figure out my mistake.
------------------------------------------------------------------------
[2015-01-06 01:25:02] requinix@php.net
XMLWriter is a stream writer: once you've started writing a subelement you cannot "go
back" and write an attribute.
Changing to a doc bug as I don't see this caveat mentioned anywhere.
------------------------------------------------------------------------
[2015-01-06 00:58:29] bas5winkel at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.xmlwriter-write-attribute
---
If you intermix writing sub-elements and attributes, any attributes that are written after the first
sub-element are ignored/discarded.
Test script:
---------------
<?php
$xml->startElement('element');
$xml->writeAttribute('attr1', 0);
$xml->writeElement('subelem', 0);
$xml->writeAttribute('attr2', 0);
$xml->endElement();
?>
Expected result:
----------------
<element attr1=0 attr2=0>
<subelem>0</subelem>
</element>
Actual result:
--------------
<element attr1=0>
<subelem>0</subelem>
</element>
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=68756&edit=1
Thread (2 messages)