Hi!
I have this script which creates an xml file from sql data:
<?php
include ('common_db.php');
$link_id = db_connect();
//-------------------------------------------------
//Do equijoin query to pull out all combined rows
//--------------------------------------------------
$tablename1 = "Article";
$tablename2 = "Image";
$query = "SELECT Article.ArticleTitle, Article.ArticleDate, Article.ArticleEntry, Image.ImageLoc, Image.ImageDescription FROM $tablename1, $tablename2 WHERE Article.ArticleImage = Image.ImageID";
$result = mysql_query($query, $link_id);
//--------------------------------------------------
//Create Dom object to transfer data to xml document
//--------------------------------------------------
$doc = new DomDocument('1.0', 'UTF-8');
//-----------------
//create root node
//-----------------
$root = $doc->createElement('News');
$root = $doc->appendChild($root);
//-----------------
//Start adding data
//-----------------
while($row = mysql_fetch_assoc($result)) {
//---------------------
//add node for each row
//---------------------
$occ = $doc->createElement($tablename1);
$occ = $root->appendChild($occ);
foreach ($row as $fieldname => $fieldvalue) {
$child = $doc->createElement($fieldname);
$child = $occ->appendChild($child);
$value = $doc->createTextNode($fieldvalue);
$value = $child->appendChild($value);
} // foreach
} // while
//---------------------------
//get completed xml document
//---------------------------
$xml_string = $doc->saveXML();
$_SESSION['xmlfile'] = $xml_string;
//echo "$xml_string";
//-----------------
//set file to write
//------------------
$xmlfile = 'lp2ect2.xml';
//----------------
//open file
//----------------
$fh = fopen($xmlfile, 'w') or die('Could not open file!');
//----------------------------
//write to file
//----------------------------
fwrite($fh, "$xml_string") or die('Could not write to file');
//-------------
//close file
//-------------
fclose($fh);
echo "<p><a href=\"transXSL.php\">view xml file?</a></p>";
?>
When you click the link, it takes you to a script to place the XSL and XML files together for rendering in the browser:
<?php
//-------------------------------
//TRANSFORMATION WITH PHP
//-------------------------------
$xsl_filename= "web.xsl";
$xml_filename= "lp2ect2.xml";
$doc = new DOMDocument();
$xsl = new XSLTProcessor();
$doc->load($xsl_filename);
$xsl->importStyleSheet($doc);
$doc->load($xml_filename);
echo $xsl->transformToXML($doc);
?>
Problem: This was working, but now I get an error and no output:
Warning: DOMDocument::load() [function.load]: Input is not proper UTF-8, indicate encoding ! Bytes: 0xA3 0x36 0x30 0x30 in
/_MPA/lp2ect2.xml, line: 23 in /_MPA/transXSL.php on line 16
I don't really understand this error, and I have failed to find a suitable answer through search engines.
Any ideas?