Access PHP Generated XML

lucyfer

New Member
I'm working on outputting data from MySQL database in XML format, so I made a php file that displays data from database in XML format on the page.\[code\]<?php// Return all existing nid in array (Different types of form);function nid(){ $query = "SELECT w.nid FROM webform w"; $result = mysql_query($query); $table = array(); while ($row = mysql_fetch_row($result)){ $table[] = $row[0]; } return $table;}// Return existing rows of corresponding nidfunction sid($nid){ $query = "SELECT ws.sid FROM webform_submissions ws WHERE ws.nid = $nid"; $result = mysql_query($query); $table = array(); while ($row = mysql_fetch_row($result)){ $table[] = $row[0]; } return $table; }// Return corresponding components of nid;function cid($nid){ $query = "SELECT wc.form_key FROM webform_component wc WHERE wc.nid = $nid ORDER BY wc.cid ASC"; $result = mysql_query($query); $table = array(); while ($row = mysql_fetch_row($result)){ $table[] = $row[0]; } return $table; }// Return values of fields corresponding to nid and sidfunction data($nid, $sid){ $query = "SELECT wsd.data FROM webform_submitted_data wsd WHERE wsd.nid = $nid AND wsd.sid = $sid ORDER BY wsd.sid ASC"; $result = mysql_query($query); $table = array(); while ($row = mysql_fetch_row($result)){ $table[] = $row[0]; } return $table; }// Define ConstantsDEFINE("DB_SERVER", "localhost");DEFINE("DB_USER", "root");DEFINE("DB_PASS", "");DEFINE("DB_NAME", "drupal7");//Establish Connectionmysql_connect(DB_SERVER, DB_USER, DB_PASS) or die("Unable to connect to MySQL");//Select Databasemysql_select_db(DB_NAME) or die("Could not connect to the database");$xml_output = "<?xml version=\"1.0\" ?>\n";$xml_output .= "<schema>";foreach (nid() as $nid){ $xml_output .= "<form fid=\"$nid\">\n"; foreach (sid($nid) as $sid){ $xml_output .= "<row rid=\"$sid\">\n"; for ($i = 0; $i < count(cid($nid)); $i++){ $tag_array = cid($nid); $value_array = data($nid, $sid); $tag_row = $tag_array[$i]; $value_row = $value_array[$i]; $xml_output .= "<$tag_row>\n"; $xml_output .= "$value_row\n"; $xml_output .= "</$tag_row>\n"; } $xml_output .= "</row>\n"; } $xml_output .= "</form>\n";}$xml_output .= "</schema>";header("Content-type: text/xml");echo $xml_output;mysql_close();?>\[/code\]But I can't see to find a way to access the XML data or download it as XML file.Here's how the output looks like when I run it.
gorjF.png
Thanks in advance
 
Back
Top