Skip to main content

Create XML File From Mysql Table

How to create XMLFile Form Mysql Table


function createXMLFile($result, $feildLength, $dir) {
$headers = array();
$xmlData = array();
$str = "";
$counter = 0;

for ($i=0;$i<$feildLength;$i++) {
array_push($headers, mysql_field_name($result, $i));
}
$xmlFileData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
while ($row = mysql_fetch_array($result)) {
for ($i=0;$i<$feildLength;$i++) {
$str .= "<".trim($headers[$i]).">" . escapeXMLEntities(trim($row[$i])) . "</".trim($headers[$i]).">\n";
$counter++; //increment column#
if ($counter == $feildLength) { //new row
array_push($xmlData, "<record>\n" . $str . "</record>\n");
$str = "";
$counter = 0;
}
}
}
$xmlFileData .= "<records name=\"Customer_Table\">\n" . implode("", $xmlData) . "</records>";


$f = fopen($dir."xmlDataFile.xml", 'w+') or die("Can not create file: xmlDataFile.xml");
fwrite($f, $xmlFileData);
fclose($f);
}


function escapeXMLEntities($xml) { // this will escape xml entities

$xml = str_replace("&", "&", $xml);
$xml = str_replace("<", "<", $xml);
$xml = str_replace(">", ">", $xml);
$xml = str_replace("\"", """, $xml);
$xml = str_replace("'", "'", $xml);

return $xml;
}

# Call this function

createXMLFile(mysql_query('select * from Customer'), 10, "/Folder/");


Comments

Popular posts from this blog

Flex Interview Questions

1) What is Flex? Flex is used to devleop Rich Internet Application (RIA) You can both desktop & web based applicaiton.It is markup language and object-oriented languages its many syntax match with flash action script. Flex Developers use typically five distinct phases to develoep Rich Internet Application. Design Configure Build Deploy Secure 2) How do i get Page URL and Query String ? We can use mx.core.Application.application.url (mx.core)package to work with current page URL. & query string. 3) Describe flex component file types ? There are following file types we can use in flex. extension .mxml - a component implemented as an MXML file. extension .as - a component implemented as an ActionScript class. extension .swc - a SWC file contains components in a packge. 4) Difference between target & currentTarget ? target : This property is set by the dispatchEvent() method. You cannot change this to a different object. currentTarget : This property is set by component instan

How to Format My Source Code For Blogger ?

How to format my source code for blogger, blog, Blogging, weblog & website ? Now you can format you source code for blogger, blog, Blogging, weblog & website using online source code formatter. This application build in javascript. This source code beautifier or formatter provide for your blogger, Blog and websites a good code indentation. You can can format your source code with alternative background using <pre> tag. It does not add unnecessary tags in formatted source code excpet <pre> and <code> so just try onto your source code for blog or blogging & website posts . This is absolutly free online line source code formatter tool for your blogger & website. http://codeformatter.blogspot.com/ See example.. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> <META NAME="Generator" CONTENT=""> <META NAME="A