DomDocument and Invalid Character Error
Posted: Sun Mar 29, 2009 1:07 am
Below is the code that im trying to get to work.. it works fine except when i try to enter a path using $image_path to add it before the $field_name. Then i get a "Invalid Character Error" due to the / in the path. I've been trying for a while to find answers and can't seem to find anything... unless its just a limitation of DomDocument. Any help would be appreciated!
Code: Select all
$query = "SELECT med_file, med_title FROM media WHERE `med_album_id` = 3 ORDER BY `med_date` DESC";
$resultID = mysql_query($query, $linkID) or die("Data not found.");
$table_id = 'test';
$image_path = "/path/";
$doc = new DomDocument('1.0');
$root = $doc->createElement('content');
$root = $doc->appendChild($root);
while($row = mysql_fetch_assoc($resultID)) {
$occ = $doc->createElement('image');
$occ = $root->appendChild($occ);
// add a child node for each field
foreach ($row as $fieldname => $fieldvalue) {
$fieldname = $image_path . $fieldname;
$child = $doc->createElement($fieldname);
$child = $occ->appendChild($child);
$value = $doc->createTextNode($fieldvalue);
$value = $child->appendChild($value);
} // foreach
} // while
$xml_string = $doc->saveXML();
echo $xml_string;