How to generate xml file using php?
I want to create a huge of data,that I retrieve from database.
How to generate xml file using php?
I want to create a huge of data,that I retrieve from database.
That’s what JREAM’s example does.
but I want it generate in .xml file?
can u show how?
I recently did this, I used DomDocument and it’s pretty sweet. Here’s a snippet of my code, you’ll get the idea
$doc = new DomDocument();
$rss = $doc->createElement('rss');
$rss->setAttribute('version', '2.0');
$rss->setAttribute('xmlns:atom', 'http://www.w3.org/2005/Atom');
$channel = $doc->createElement('channel');
$doc->appendChild($rss);
$rss->appendChild($channel);
$this->DB->Query("SELECT anything FROM wherever");
$Data = $this->DB->Get();
foreach ($Data as $a)
{
$item = $doc->createElement('item');
$item->appendChild($i_title);
$channel->appendChild($item);
}
header('Content-type: text/xml');
echo $doc->saveXML();