Re[2]: [PHP] XML dom encode
| From: | Tom Rogers | Date: | Fri, 04 Oct 2002 15:53:02 +0000 |
| Subject: | Re[2]: [PHP] XML dom encode | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-118884@lists.php.net to get a copy of this message | ||
Hi,
Untested but it would be something like this:
<?php
header("Content-Type: application/xml");
//query database records
$connection = mysql_connect("localhost", "user", "pass") or
die("can't connect");
mysql_select_db("webbish");
$query = "SELECT id, title, artist FROM xmldb";
$result = mysql_query($query);
if(mysql_num_rows($result) > 0){
//Create DomDocument
ob_start();
echo '<?xml version="1.0"
encoding="iso-8859-1"?><cds/>';
$buffer = ob_get_contents();
ob_end_clean();
$doc = domxml_open_mem($buffer);
//Get root node
$root = $doc->document_element();
//Iterate through result set
while(list($id, $title, $artist) = mysql_fetch_row($result)){
//create item node
$record = $root->new_child("cd", "");
$record->set_attribute("id", $id);
//Attach title and artist as children of item node
$record->new_child("title", $title);
$record->new_child("artist", $artist);
}
echo $doc->dumpmem();
}
?>
--
regards,
Tom