note 119937 deleted from function.xmlwriter-write-attribute by cmb

From: Date: Sun, 20 Sep 2020 15:43:16 +0000
Subject: note 119937 deleted from function.xmlwriter-write-attribute by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-215161@lists.php.net to get a copy of this message
Note Submitter: Paul ---- 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.

« previous php.notes (#215161) next »