This param should be used only after openMemory() call:
<?php
$version = '1.0';
$encoding = 'UTF-8';
$rootName = 'root';
$xml = new XMLWriter();
$xml->openMemory();
$xml->setIndent(true);
$xml->startDocument($version, $encoding);
$xml->startElement($this->rootName);
// .. add more elements here
$xml->endElement();
echo $xml->outputMemory();
?>