Jump to content

Recommended Posts

Is there a way that I can tweak the following code so that the root nodes have different names?

 

At the moment the xml file is creating a root node for each booking called booking so when I take the xml into flash it is calling it badly formed xml due to the repitition of <booking></booking>

 

//sql_query
$table_id = 'booking'; 	
$query = "SELECT * FROM $table_id WHERE (booking.bookingDate = curDate()) AND roomID = 1 ORDER BY startTime";
$room1 = mysql_query($query);


//create a new DOM document
$doc = new DOMDocument('1.0');

//create root element
$root = $doc->createElement('root');
$root = $doc->appendChild($root);

//process one row at at time
while($row = mysql_fetch_assoc($room1)){

//add node for each row
$occ = $doc->createElement($table_id);
$occ = $doc->appendChild($occ);

//add achild for each field
foreach ($row as $fieldname => $fieldvalue){

     $child = $doc->createElement($fieldname);
    	$child = $occ->appendChild($child);


$value = $doc->createTextNode($fieldvalue);
    	$value = $child->appendChild($value);
}
}

   $xml_string = $doc->saveXML();

echo $xml_string;

mysql_free_result($room1);
?>

Link to comment
https://forums.phpfreaks.com/topic/226441-tweaking-the-xml-content/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.