spangle1187 Posted February 2, 2011 Share Posted February 2, 2011 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/226441-tweaking-the-xml-content/ Share on other sites More sharing options...
salathe Posted February 2, 2011 Share Posted February 2, 2011 You shouldn't be appending multiple elements to the document. In short, your line which contains $doc->appendChild($occ) should be changed to $root->appendChild($occ). Quote Link to comment https://forums.phpfreaks.com/topic/226441-tweaking-the-xml-content/#findComment-1168785 Share on other sites More sharing options...
spangle1187 Posted February 2, 2011 Author Share Posted February 2, 2011 What a legend! Quote Link to comment https://forums.phpfreaks.com/topic/226441-tweaking-the-xml-content/#findComment-1168813 Share on other sites More sharing options...
salathe Posted February 2, 2011 Share Posted February 2, 2011 Where? Is he behind me? *looks around* (P.S. You're welcome. ) Quote Link to comment https://forums.phpfreaks.com/topic/226441-tweaking-the-xml-content/#findComment-1168939 Share on other sites More sharing options...
spangle1187 Posted February 2, 2011 Author Share Posted February 2, 2011 I am enjoying learning php even when I scream at the screen and its amazing how you guys and girls spot minor syntax errors at fifty feet and you all seem to know at least three different possible solutions to the same problem Quote Link to comment https://forums.phpfreaks.com/topic/226441-tweaking-the-xml-content/#findComment-1168949 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.