Jump to content

Generate XML with PHP


jeremy.saenz

Recommended Posts

Hello, I am fairly new to the PHP and after numerous google searches, I have found that PHP is a possible solution for generating XML documents. I wish to generate XML documents with PHP, gathering information from either a mySQL database, or through HTML forms.

Below as a sample of the XML code I wish to generate on my server.

[code]<?xml version="1.0" encoding="utf-8"?>
<chart print_title="Company Sales" print_footer="This is an example" type="pie">
<section title="Jan" color="0x9F00FF" value="4150" />
<section title="Feb" color="0x555555" value="2133" />
<section title="Mar" color="0x9F00FF" value="6486" />
<section title="Apr" color="0x555555" value="5520" />
<section title="May" color="0x9F00FF" value="3350" />
<section title="Jun" color="0x555555" value="5733" />
<section title="Jul" color="0x9F00FF" value="5986" />
<section title="Aug" color="0x555555" value="4120" />
<section title="Sep" color="0x9F00FF" value="3550" />
<section title="Oct" color="0x555555" value="4533" />
<section title="Nov" color="0x9F00FF" value="5936" />
<section title="Dec" color="0x555555" value="6120" />
</chart>[/code]
Link to comment
https://forums.phpfreaks.com/topic/26848-generate-xml-with-php/
Share on other sites

here is example to start u off from one of my websites in php:

//get employees from database... add to $employeeList
$host = "localhost"; $user = "bleh"; $pass = "blah"; 
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");

$db = "intranet";
mysql_select_db($db) or die ("Unable to select database!");
$result = mysql_query($Query) or die ("Error in query: $query. ".mysql_error());
while($row = mysql_fetch_array($result))
{
$employeeList[]= array( $row['ID'], $row['name'] );
}


header("Content-Type: text/xml");
echo('<?xml version="1.0" standalone="no" ?>');

echo '<empList>';
foreach($employeeList as $employee)
{
echo "<employee>";
    echo "<empID>". $employee[0] ."</empID>";
    echo "<name>". $employee[1] ."</name>";
echo "</employee>";
}
echo '</empList>';
Link to comment
https://forums.phpfreaks.com/topic/26848-generate-xml-with-php/#findComment-122865
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.