Add example for intermixing sub-elements and attributes

This integrates user notes 103498 and 119937.


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@350605 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Christoph Michael Becker 2020-09-20 16:39:23 +00:00
parent 9ea98fa298
commit 2716a63905

View file

@ -58,6 +58,40 @@
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example xml:id="xmlwriter-write-attribute.example.intermix">
<title>Intermixing Sub-elements and Attributes</title>
<para>
If writing sub-elements and attributes is intermixed, any attempt to write
attributes after the first sub-element will fail and return false.
</para>
<programlisting role="php">
<![CDATA[
<?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();
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
bool(false)
<element attr1="0"><subelem>0</subelem></element>
]]>
</screen>
</example>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>