If you intermix writing sub-elements and attributes, any attributes that are written after the first sub-element are ignored/discarded:
<?php
$xml->startElement('element');
$xml->writeAttribute('attr1', 0);
$xml->writeElement('subelem', 0);
$xml->writeAttribute('attr2', 0);
$xml->endElement();
?>
Outputs:
<element attr1=0>
<subelem>0</subelem>
</element>
This is stupid, but the way it works as of PHP 5.2.4.