Page 1 of 1
Table Data to XML File
Posted: Tue Feb 17, 2004 10:29 am
by mccommunity
I am trying to take a tables data and output and XML file from it. I am not really sure how though. Does anyone have a script to do this or can point me in the right direction so I can see samles of how this is done? Thanks.
Posted: Tue Feb 17, 2004 10:37 am
by McGruff
You could, for example, create an .xml template and embed some echo calls.
Declare all the vars then simply include the template to print to client.
Or wrap it up in a buffer to write to file.
Posted: Tue Feb 17, 2004 11:15 am
by ol4pr0
I am not sure if you want to retrieve DB information and have a xml file created.. but if its like that.. this is what i use.
Code: Select all
// db connection bla... bla..
$num = mysql_num_rows($result);
$file= fopen("resulta.xml", "w");
$_xml ="<?xml version="1.0" encoding="UTF-8"?>\r\n";
$_xml .="<cardat>\r\n";
$_xml .="<envctrol>\r\n";
if(mysql_num_rows($result) > 0){
while($rows = mysql_fetch_array($result))
{
//$_xml .="\t<dato="" . $rows["dato"] . "">\r\n";$_xml .="\t</dato>\r\n";
$_xml .="\t<tipo-operador>="08">\r\n";$_xml .="\t</tipo-operador>\r\n";
$_xml .="\t<codigo-operador> ="5519">\r\n";$_xml .="\t</codigo-operador>\r\n";
$_xml .="\t<nume-regist-cabe>="1">\r\n";$_xml .="\t</nume-regist-cabe>\r\n";
$_xml .="\t<nume-regist-cabe-dav>="1">\r\n";$_xml .="\t</nume-regist-cabe-dav>\r\n";
$_xml .="\t<nume-regist-doc-transp>="1">\r\n";$_xml .="\t</nume-regist-doc-transp>\r\n";
$_xml .="\t<t-fob-doc-transp>="20">\r\n";$_xml .="\t</t-fob-doc-transp>\r\n";
$_xml .="\t<t-peso-bruto-manifdo>="20">\r\n";$_xml .="\t</t-peso-bruto-manifdo>\r\n";
$_xml .="\t<clave-electronica>="5519">\r\n";$_xml .="\t</clave-electronica>\r\n";
// and 250 lines more
}
}
else
{
$_xml .="\t<Query_Empty>="No Resulta">\r\n";
$_xml .="\t</Query_Empty>\r\n";
}
$_xml .="</envctrol>";
$_xml .="</cardat>";
fwrite($file, $_xml);
fclose($file);
echo "XML formato list. <a href="resulta.xml">Por Aqui el formato XML.</a>";
?>
Code: Select all
// $_xml .="\t<xml tag>="" . $rows["some field"] . "">\r\n";$_xml .="\t</xml tag>\r\n";
Hope that helps.