XMLWriter::flush() basic usage with XMLWriter::openMemory() :
<?php
$xml = new XMLWriter();
$xml->openMemory();
$xml->startDocument();
$xml->writeElement('message', 'Hello World!');
$xml->endDocument();
echo $xml->flush();
/*
Produces :
<?xml version="1.0"?>
<message>Hello World!</message>
*/
?>