openMemory(); $xw->startDocument('1.0','utf8'); $xw->startElement('tournament'); foreach ($tournament as $key => $value) { $xw->writeElement ($key, $value); } $sth = mysql_query("SELECT * FROM Questions WHERE ParentId =$id"); while ($question = mysql_fetch_assoc($sth) ) { $xw->startElement('question'); foreach ($question as $key => $value) { $xw->writeElement($key, $value); } $xw->endElement('question'); } $xw->endElement('tournament'); $xmlResult = $xw->outputMemory(true); $xmlResult = preg_replace('/\>\s*\\n<", $xmlResult); header("Content-Type: text/xml"); print $xmlResult; ?>