<?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
            $doc = new_xmldoc("1.0");
 
            
            //Add root note
            $root = $doc->add_root("cds");
 
            //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();
} 
            ?>
 
 
makes a xml doc that looks like this:
 
  <?xml version="1.0" ?> 
- <cds>
- <cd id="1">
  <title>sdfsdfsdf</title> 
  <artist>ssdfsdf</artist> 
  </cd>
- <cd id="2">
  <title>asdf</title> 
  <artist>asdf</artist> 
  </cd>
- <cd id="3">
  <title>sdfasdf</title> 
  <artist>涩</artist> 
  </cd>
  </cds>
 
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:
 
  <?xml version="1.0" encoding=”iso-8859-1” ?> 
- <cds>
- <cd id="1">
  <title>sdfsdfsdf</title> 
  <artist>ssdfsdf</artist> 
  </cd>
- <cd id="2">
  <title>asdf</title> 
  <artist>asdf</artist> 
  </cd>
- <cd id="3">
  <title>sdfasdf</title> 
  <artist>涩</artist> 
  </cd>
  </cds>
 
Any Ideas how to do this? I’ve been searching the net for solutions without any 
results.
 
Thanks David
 
 
 
 


Reply via email to