encoding = "UTF-8"; $root = $doc->createElement("songs"); $root->appendChild(new DOMAttr("totalsongs", $totalRows)); $doc->appendChild($root); while($row = @mysql_fetch_assoc($result)) { $song = $doc->createElement("song"); foreach($row as $key => $value) { $keypair = $doc->createElement($key); $keypair->appendChild($doc->createTextNode(utf8_encode($value))); $song->appendChild($keypair); } $root->appendChild($song); } $output = @$doc->saveXML(); header("Content-Length: ".strlen($output)); if(!empty($_SERVER["HTTP_ACCEPT_ENCODING"])) { header("Uncompressed-Length: ".strlen($output)); } if(ini_get("zlib.output_compression") != "1" && strstr($_SERVER["HTTP_ACCEPT_ENCODING"], 'gzip')) { $output = gzencode($output, 9); header("Content-Encoding: gzip"); } echo $output; } @mysql_free_result($result); ?>