Code: Select all
<?php
require("../sqlScripts/dbconnection.php");
//in this file I'm going to make xml foile of the database product items
//////////////////////////////////////////////////////////////////////////
$sql = "SELECT * FROM products";
$result = mysql_query($sql);
// create a new XML document
$doc = new DomDocument();
$doc->formatOutput = true;
// create root node
$root = $doc->createElement('products');
$root = $doc->appendChild($root);
// process one row at a time
while($row = mysql_fetch_assoc($result)) {
// add node for each row
$occ = $doc->createElement('product');
$occ = $root->appendChild($occ);
// add a child node for each field
print_r($row);
foreach ($row as $fieldname => $fieldvalue) {
//$child = $doc->createElement($fieldname);
$new = $doc->createElement($fieldname);
$new->appendChild($doc->createTextNode($fieldvalue));
/* $child = $occ->appendChild($child);
$value = $doc->createTextNode($fieldvalue);
$value = $child->appendChild($value);*/
} // foreach
} // while
// get completed xml document
$xml_string = $doc->saveXML();
$doc->save("write2.xml");
echo $xml_string;
?>Uncaught exception 'DOMException' with message 'Invalid Character Error' in C:\wamp\www\newOstore\administrator\product_xml_creation.php on line 23