The attribute value can be set with XMLWriter::text(), e.g.:
<?php
$writer = new XMLWriter;
$writer->openURI('php://output');
$writer->startDocument('1.0', 'UTF-8');
$writer->startElement('response');
$writer->startElement('status');
$writer->startAttribute('code');
$writer->text('500');
$writer->endAttribute();
$writer->endElement();
$writer->endElement();
$writer->endDocument();
?>
... generates:
<?xml version="1.0" encoding="UTF-8"?>
<response><status code="500"/></response>