Hi,

Friday, October 4, 2002, 10:14:31 PM, you wrote:
 
D�J> <?php
D�J> header("Content-Type: application/xml");
 
D�J> //query database records
D�J> $connection = mysql_connect("localhost", "user", "pass") or die("can't connect");
D�J> mysql_select_db("webbish");
 
D�J> $query = "SELECT id, title, artist FROM xmldb";
D�J> $result = mysql_query($query);
 
D�J> if(mysql_num_rows($result) > 0){
D�J>             //Create DomDocument
D�J>             $doc = new_xmldoc("1.0");
 
            
D�J>             //Add root note
D�J>             $root = $doc->add_root("cds");
 
D�J>             //Iterate through result set
D�J>             while(list($id, $title, $artist) = mysql_fetch_row($result)){
                        
D�J>                         //create item node
D�J>                         $record = $root->new_child("cd", "");
D�J>                         $record->set_attribute("id", $id);
                        
D�J>                         //Attach title and artist as children of item node
D�J>                         $record->new_child("title", $title);
D�J>                         $record->new_child("artist", $artist);
D�J>             }
 
            
D�J>             echo $doc->dumpmem();
D�J> } 
D�J>             ?>
 
 
D�J> makes a xml doc that looks like this:
 
D�J>   <?xml version="1.0" ?> 
D�J> - <cds>
D�J> - <cd id="1">
D�J>   <title>sdfsdfsdf</title> 
D�J>   <artist>ssdfsdf</artist> 
D�J>   </cd>
D�J> - <cd id="2">
D�J>   <title>asdf</title> 
D�J>   <artist>asdf</artist> 
D�J>   </cd>
D�J> - <cd id="3">
D�J>   <title>sdfasdf</title> 
D�J>   <artist>?</artist> 
D�J>   </cd>
D�J>   </cds>
 
D�J> But I need to modify this script so that I can set the encoding of the xml 
document to ISO-8859-1 so it would look like this:
 
D�J>   <?xml version="1.0" encoding=�iso-8859-1� ?> 
D�J> - <cds>
D�J> - <cd id="1">
D�J>   <title>sdfsdfsdf</title> 
D�J>   <artist>ssdfsdf</artist> 
D�J>   </cd>
D�J> - <cd id="2">
D�J>   <title>asdf</title> 
D�J>   <artist>asdf</artist> 
D�J>   </cd>
D�J> - <cd id="3">
D�J>   <title>sdfasdf</title> 
D�J>   <artist>?</artist> 
D�J>   </cd>
D�J>   </cds>
 
D�J> Any Ideas how to do this? I�ve been searching the net for solutions without any 
results.
 
D�J> Thanks David
 
One way to force it:
<?
ob_start();
echo '<?xml version="1.0" encoding="iso-8859-1"?><cds/>';
$buffer = ob_get_contents();
ob_end_clean();
$dom = domxml_open_mem($buffer);
echo '<pre>';
echo htmlentities($dom->dump_mem(true));
echo '</pre>';
?>

-- 
regards,
Tom


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to