BygMony Posted February 26, 2007 Share Posted February 26, 2007 Ok I've been working on this for two weeks. I am using PHP/MySql to store info for a XML formatted doc. I used the technique from www.gotoandlearn.com to produce XML with PHP. I added the ability to write the XML file that show up in IE and that works great. I recently made a change to have keywords in a separate DB because I need to have the keywords inputted separately in the XML. This XML file is used for SCORM compliancy based on the ADL website https://adlregistry.dtic.mil/ (https://adlregistry.dtic.mil/6/index2_7.htm). The problem now is that when I run the script to produce the XML page via IE and write it into the xml folder it prints the keyword in IE but it will not write them in the .xml file. It writes all the other data but just shows the do while loop i have. Below is the code. To me it appears that the variable is not being reconized in the bottome write file portion of the code. This was done with Dreamweaver and Handcoding and reworked code off the internet. The page is intitated by clicking on a link that displays the course title and takes you to a page that displays all the course info in XML format. Thanks BygMony <?php require_once('../Connections/scorm.php'); ?> <?php $colname_rsScorm = "-1"; if (isset($_GET['SCO_Description'])) { $colname_rsScorm = (get_magic_quotes_gpc()) ? $_GET['SCO_Description'] : addslashes($_GET['SCO_Description']); } $colname2_rsScorm2 = "-1"; if (isset($_GET['SCO_Description'])) { $colname2_rsScorm2 = (get_magic_quotes_gpc()) ? $_GET['SCO_Description'] : addslashes($_GET['SCO_Description']); } mysql_select_db($database_scorm, $scorm); $query_rsScorm = sprintf("SELECT * FROM sco_metadata WHERE COI_Number = %s", $colname_rsScorm); $rsScorm = mysql_query($query_rsScorm, $scorm) or die(mysql_error()); $row_rsScorm = mysql_fetch_assoc($rsScorm); $totalRows_rsScorm = mysql_num_rows($rsScorm); mysql_select_db($database_scorm, $scorm); $query_rsScorm2 = sprintf("SELECT * FROM keywords WHERE COI_Number = %s", $colname2_rsScorm2); $rsScorm2 = mysql_query($query_rsScorm2, $scorm) or die(mysql_error()); $row_rsScorm2 = mysql_fetch_assoc($rsScorm2); $totalRows_rsScorm2 = mysql_num_rows($rsScorm2); $results2 = mysql_query($query_rsScorm2); $line2 = mysql_fetch_assoc($results2); $results = mysql_query($query_rsScorm); $line = mysql_fetch_assoc($results); ?> <?php /* $line["database field"] must make upper/lower case */ echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"; echo "<registryTransaction xmls=\"http://hdl.cordra.net/2000.2.1/ADL-R-Reg-T\" xmlns:lom=\"http://Itsc.ieee.org/xsd/LOM\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://Itsc.ieee.org/xsd/LOMhttp://hdl.cordra.net/2000.2/adlreg-lom?VData=version&id=1http://hdl.cordra.net/2000.2.1/ADL-R-Reg-Thttp://hdl.cordra.net/2000.2.1/ADL-R-Reg-T?VData=version&=1\">\n"; echo "<course_metadata>\n"; echo "<metadata>\n"; echo "<mod_title>" . $line["Module_Title"] . "</mod_title>\n"; echo "<lesson_title>" . $line["Lesson_Title"] . "</lesson_title>\n"; echo "<coi_num>" . $line["COI_Number"]. "</coi_num>\n"; echo "<version>" . $line["Version"] . "</version>\n"; //work great, loops and displays all keywords from keyword database do { echo "<lom:keyword>\n"; echo "<lom:string language=\"en-US\">" . $line2["Keywords"] . "</lom:string>\n"; echo "</lom:keyword>\n"; } while($line2 = mysql_fetch_assoc($results2)); echo "<status>" . $line["Status"] ."</status>\n"; echo "<sco_description>" . $line["SCO_Description"] . "</sco_description>\n"; echo "<date_created>" . $line["Date_Created"] . "</date_created>\n"; echo "<security_classification>" . $line["Security_Classification"] . "</security_classification>\n"; echo "<format>" . $line["Format"] . "</format>\n"; echo "<document>" . $line["Document_Handler"] . "</document>\n"; echo "<interactivity_level>" . $line["Interactivity_Level"] . "</interactivity_level>\n"; echo "<learning_resource_type>" . $line["Learning_Resource_Type"] . "</learning_resource_type>\n"; echo "<contribute>" . $line["Contribute"] . "</contribute>\n"; echo "<copyright>" . $line["Copyright_restrictions"] . "</copyright>\n"; echo "<location>" . $line["Location"] . "</location>\n"; echo "<aggregation_level>" . $line["Aggregation_Level"] . "</aggregation_level>\n"; echo "<knowledge_type>" . $line["Knowledge_Type"] . "</knowledge_type>\n"; echo "<terminal_learning_obj>" . $line["Terminal_Learning_Obj"] . "</terminal_learning_obj>\n"; echo "</metadata>\n"; echo "</course_metadata>\n"; echo "</registryTransaction>\n"; //Write .xml file to folder $myFile = str_replace(' ','',$line["Module_Title"]). '.xml'; $fh = fopen("xml/".$myFile, 'w') or die("can't open file"); $stringData = "<?xml version=\"1.0\" encoding=\"utf-8\" ?> <registryTransaction xmls=\"http://hdl.cordra.net/2000.2.1/ADL-R-Reg-T\" xmlns:lom=\"http://Itsc.ieee.org/xsd/LOM\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://Itsc.ieee.org/xsd/LOMhttp://hdl.cordra.net/2000.2/adlreg-lom?VData=version&id=1http://hdl.cordra.net/2000.2.1/ADL-R-Reg-Thttp://hdl.cordra.net/2000.2.1/ADL-R-Reg-T?VData=version&=1\"> <course_metadata> <metadata> <mod_title>" . $line["Module_Title"] . "</mod_title> <lesson_title>" . $line["Lesson_Title"] . "</lesson_title> <coi_num>" . $line["COI_Number"] . "</coi_num> <version>" . $line["Version"] . "</version> <!--This will not loop and it prints the loop as you see it.--> do { <lom:keyword> <lom:string language=\"en-US\">" . $line2["Keywords"] . "</lom:string> </lom:keyword> } while($line2 = mysql_fetch_assoc($results2));<!--It calls $results2 resource id #6 and deletes $line2. Everything else prints out to a text file correctly--> <status>" . $line["Status"] ."</status> <sco_description>" . $line["SCO_Description"] . "</sco_description> <date_created>" . $line["Date_Created"] . "</date_created> <security_classification>" . $line["Security_Classification"] . "</security_classification> <format>" . $line["Format"] . "</format> <document>" . $line["Document_Handler"] . "</document> <interactivity_level>" . $line["Interactivity_Level"] . "</interactivity_level> <learning_resource_type>" . $line["Learning_Resource_Type"] . "</learning_resource_type> <contribute>" . $line["Contribute"] . "</contribute> <copyright>" . $line["Copyright_restrictions"] . "</copyright> <location>" . $line["Location"] . "</location> <aggregation_level>" . $line["Aggregation_Level"] . "</aggregation_level> <knowledge_type>" . $line["Knowledge_Type"] . "</knowledge_type> <terminal_learning_obj>" . $line["Terminal_Learning_Obj"] . "</terminal_learning_obj> </metadata> </course_metadata> </registryTransaction>\n"; fwrite($fh, $stringData); fclose($fh); mysql_free_result($rsScorm); mysql_free_result($rsScorm2); ?> ---------------------------------XML FILE THAT GETS WRITTEN-------------------------------------- <?xml version="1.0" encoding="utf-8" ?> <registryTransaction xmls="http://hdl.cordra.net/2000.2.1/ADL-R-Reg-T" xmlns:lom="http://Itsc.ieee.org/xsd/LOM" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://Itsc.ieee.org/xsd/LOMhttp://hdl.cordra.net/2000.2/adlreg-lom?VData=version&id=1http://hdl.cordra.net/2000.2.1/ADL-R-Reg-Thttp://hdl.cordra.net/2000.2.1/ADL-R-Reg-T?VData=version&=1"> <course_metadata> <metadata> <mod_title>Griffin</mod_title> <lesson_title>BygMony</lesson_title> <coi_num>990923</coi_num> <version>1</version> <!--This will not loop and it prints the loop as you see it.--> do { <lom:keyword> <lom:string language="en-US"></lom:string> </lom:keyword> } while( = mysql_fetch_assoc(Resource id #6));<!--It calls Resource id #6 resource id #6 and deletes . Everything else prints out to a text file correctly--> <status>Green</status> <sco_description>None.</sco_description> <date_created>Nov 29, 2005</date_created> <security_classification>Classified</security_classification> <format>full</format> <document>FOUO</document> <interactivity_level>Category 1</interactivity_level> <learning_resource_type>Web based</learning_resource_type> <contribute>none</contribute> <copyright>none</copyright> <location>www.jfcom.mil</location> <aggregation_level>6</aggregation_level> <knowledge_type>Process</knowledge_type> <terminal_learning_obj>none.</terminal_learning_obj> </metadata> </course_metadata> </registryTransaction> Link to comment https://forums.phpfreaks.com/topic/40184-php-to-xml-and-write-an-xml-file/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.