//connect to host
mysql_connect($config['mysql_host'],$config['mysql_user'],$config['mysql_pass']);
//select database
mysql_select_db($config['db_name']) or die( "Unable to select database");
$xml = "”;
$root_element = $config[‘table_name’].”s”;
$xml .= “”;
//select all items in table
$sql = “SELECT * FROM “.$config[‘table_name’];
$result = mysql_query($sql);
if (!$result) {
die(‘Invalid query: ‘ . mysql_error());
}
if(mysql_num_rows($result)>0)
{
while($result_array = mysql_fetch_assoc($result))
{
$xml .= “”;
//loop through each key,value pair in row
foreach($result_array as $key => $value)
{
//$key holds the table column name
$xml .= “”;
//embed the SQL data in a CDATA element to avoid XML entity issues
$xml .= “”;
//and close the element
$xml .= “”;
}
$xml.=””;
}
}
//close the root element
$xml .= “”;
//send the xml header to the browser
header (“Content-Type:text/xml”);
//output the XML data
echo $xml;
?>
Untitled Document
when i run this code……I get the error message
This page contains the following errors:
error on line 1 at column 1418: error parsing attribute name
Below is a rendering of the page up to the first error.
plzz…….help…..its very urgent
Thanks,
Adesh
<?php
//Database configuration
$config['mysql_host'] = "localhost";
$config['mysql_user'] = "root";
$config['mysql_pass'] = "dipalmodi";
$config['db_name'] = "xml";
$config['table_name'] = "my_data";
//connectto host
mysql_connect($config['mysql_host'],$config['mysql_user'],$config['mysql_pass']);
//select database
@mysql_select_db($config['db_name']) or die( "Unable to select database");
$xml = "”;
$root_element = $config[‘table_name’].”s”; //my_data
$xml .= “”;
//select all items in table
$sql = “select * from “.$config[‘table_name’];
$result = mysql_query($sql);
if(!$result)
{
die(‘Invalid Query: ‘ .mysql_error());
}
if(mysql_num_rows($result)>0)
{
while($result_array = mysql_fetch_assoc($result))
{
$xml. = “”;
//loop through each key, value pair in row
foreach($result_array as $key => $value)
{
//$key holds the table column name
$xml.=””;
//embed the SQL data in a CDATA element to avoid XML entity issues
$xml.= “”;
//and close the element
$xml.=””;
}
$xml.=””;
}
}
//close the root element
$xml.=””;
//send the xml header to the browser
header(“Content-Type:text/xml”);
//output the xml data
echo $xml;
?>
please reply me ASAP.
]]>MY CODE IS:
<?php
$config['db_name'] = "algo_marketing";
$config['table_name'] = "trade";
//connect to host
mysql_connect($config['mysql_host'],$config['mysql_user'],$config['mysql_pass']);
//select database
@mysql_select_db($config['db_name']) or die( "Unable to select database");
$xml = "”;
$root_element = $config[‘table_name’].”s”;
$xml .= “”;
//select all items in table
$sql = “SELECT * FROM “.$config[‘table_name’];
$result = mysql_query($sql);
if (!$result) {
die(‘Invalid query: ‘ . mysql_error());
}
if(mysql_num_rows($result)>0)
{
while($result_array = mysql_fetch_assoc($result))
{
$xml .= “”;
//loop through each key,value pair in row
foreach($result_array as $key => $value)
{
//$key holds the table column name
$xml .= “”;
//embed the SQL data in a CDATA element to avoid XML entity issues
$xml .= “”;
//and close the element
$xml .= “”;
}
$xml.=””;
}
}
//close the root element
$xml .= “”;
//send the xml header to the browser
header (“Content-Type:text/xml”);
//output the XML data
echo $xml;
?>
This helped me. Just put output into a variable then add this code.
$myfile = fopen(“newfile.xml”, “w”) or die(“Unable to open file!”);
fwrite($myfile, $xml);
fclose($myfile);
it will generate every time updated XML file when will refresh php.
]]>“This XML file does not appear to have any style information associated with it. The document tree is shown below.”
i am new in XML
Help me