Page 1 of 1

generate xml

Posted: Fri Sep 24, 2010 7:41 pm
by peterhall
hi guys. I have this code to generate a xml file from mysql dbase table. the problem is that code generates the xml, but only into the browser, and what i want is to generate the file. what is wrong in here?

Code: Select all

<?php require_once('Connections/incon_F.php'); ?>
<?php
// Load the XML classes
require_once('includes/XMLExport/XMLExport.php');

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_incon_F, $incon_F);
$query_create_xml = "SELECT date_bf, date_af, sum_incons FROM rfplansite_4_sum ORDER BY date_af DESC";
$create_xml = mysql_query($query_create_xml, $incon_F) or die(mysql_error());
$row_create_xml = mysql_fetch_assoc($create_xml);
$totalRows_create_xml = mysql_num_rows($create_xml);mysql_select_db($database_incon_F, $incon_F);
$query_create_xml = "SELECT date_bf, date_af, sum_incons FROM rfplansite_4_sum ORDER BY date_af DESC";
$create_xml = mysql_query($query_create_xml, $incon_F) or die(mysql_error());
$row_create_xml = mysql_fetch_assoc($create_xml);
$totalRows_create_xml = mysql_num_rows($create_xml);

// Begin XMLExport create_xml
$xmlExportObj = new XMLExport();
$xmlExportObj->setRecordset($create_xml);
$xmlExportObj->addColumn("date_af", "label");
$xmlExportObj->addColumn("date_bf", "label1");
$xmlExportObj->addColumn("sum_incons", "value");
$xmlExportObj->setMaxRecords("ALL");
$xmlExportObj->setDBEncoding("UTF-8");
$xmlExportObj->setXMLEncoding("UTF-8");
$xmlExportObj->setXMLFormat("ATTRIBUTES");
$xmlExportObj->setRootNode("chart");
$xmlExportObj->setRowNode("set");
$xmlExportObj->Execute();
// End XMLExport create_xml
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
</body>
</html>
<?php
mysql_free_result($create_xml);
?>

Re: generate xml

Posted: Fri Sep 24, 2010 8:12 pm
by requinix
The problem is that whatever you're doing with that XMLEmport class is outputting the XML instead of saving it to a file. Look through the class/documentation for some part that saves to a file.