Table Data to XML File
Moderator: General Moderators
-
mccommunity
- Forum Commoner
- Posts: 62
- Joined: Mon Oct 07, 2002 8:55 am
Table Data to XML File
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.
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.
Hope that helps.
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";