Page 1 of 1

how to generate xml file dynamically using PHP?

Posted: Wed Jan 28, 2009 1:11 am
by gadadasusrikanth
HI..........
i have to generate a xml file dynamically at runtime........So plz help me.

MY sample xml file:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xml>
    <track>
        <path>song1.mp3</path>
        <title>Track 1 - Track Title</title>
    </track>
    <track>
        <path>song2.mp3</path>
        <title>Track 2 - Track Title</title>
    </track>
    <track>
        <path>song3.mp3</path>
        <title>Track 3 - Track Title</title>
    </track>
    <track>
        <path>song4.mp3</path>
        <title>Track 4 - Track Title</title>
    </track>
    <track>
        <path>song5.mp3</path>
        <title>Track 5 - Track Title</title>
    </track>
    <track>
        <path>song6.mp3</path>
        <title>Track 6 - Track Title</title>
    </track>
    <track>
        <path>song7.mp3</path>
        <title>Track 7 - Track Title</title>
    </track>
    <track>
        <path>song8.mp3</path>
        <title>Track 8 - Track Title</title>
    </track>
    
</xml>
plz help me in generating above xml file dynamically using php...........

Re: how to generate xml file dynamically using PHP?

Posted: Wed Jan 28, 2009 1:31 am
by jothirajan
Yeah...

Here you go...

use this php code:

$ResRSSXml = mysql_query("select * from table_name");


if(mysql_num_rows($ResRSSXml)>0)
{
$xml_content = "<?xml version='1.0' encoding='utf-8' standalone='yes'?>
<rss xmlns:media='http://search.yahoo.com/mrss' version='2.0'>
<channel>";
while($ResRSS = mysql_fetch_assoc($ResRSSXml))
{
$xml_content.= '


<track>
<path>'.$ResRSS['song_name'].'</path>
<title>'.$ResRSS['title'].'</title>
</track>

';
}
$xml_content.= "</channel>
</rss>\n";

$randomno=rand(0,10000);
$xml_data = $xml_content;
$user_file='article_xml/jothi.xml';
$GotFile = false;
if($ObjDir = opendir($user_file1='article_xml/'))
{
$userFile = 'jothi.xml';
while(false !== ($fileName = readdir($ObjDir)))
{
if ($fileName != "." && $fileName != "..")
{
if(eregi($userFile.'$',$fileName))
{
$GotFile = true;
break;
}
}
}
closedir($ObjDir);
}
if($GotFile)
{
unlink('article_xml/'.$fileName);
if(touch($user_file))
$filep = fopen($user_file,'w+');
}
else
if(touch($user_file))
$filep = fopen($user_file,'w+');
fwrite($filep,$xml_data);
fclose($filep);
chmod($user_file,0777);
}

Create a folder "article_xml" and have a dummy XML file....

For every single time it will reflect the o/p according to the code.

Thanks
JOE...

Get back to me...if you want more....

Re: how to generate xml file dynamically using PHP?

Posted: Wed Jan 28, 2009 1:41 am
by gadadasusrikanth
i dont have the data base.........i have to create it in one of my directory.

Re: how to generate xml file dynamically using PHP?

Posted: Wed Jan 28, 2009 3:02 am
by jothirajan
So no problem..

Just remove the database values and table content...

Assign some var for the loop to go....

Easy....

Thanks
JOE...

Get me if you want more...

Re: how to generate xml file dynamically using PHP?

Posted: Tue Feb 03, 2009 12:06 am
by gadadasusrikanth
thn x ..........