The function XMLWriter::writeElement is used to write an element (i.e. a XML tag, an [optional] content, and a closing XML tag) in one line without sub-elements:
<?php
$oXMLout = new XMLWriter();
$oXMLout->openMemory();
$oXMLout->writeElement("quantity", 8);
$oXMLout->writeElement("price_per_quantity", 110);
print $oXMLout->outputMemory();
?>
whereas if you want to include sub-elements you have to use the XMLWriter::startElement / XMLWriter::endElement pair:
<?php
$oXMLout = new XMLWriter();
$oXMLout->openMemory();
$oXMLout->startElement("item");
$oXMLout->writeElement("quantity", 8);
$oXMLout->writeElement("price_per_quantity", 110);
$oXMLout->endElement();
print $oXMLout->outputMemory();
?>