hi

i need to create .xml file by using php dynamically...
i want the below formate...here .mp3 files from url(get parameter).....

<?xml version="1.0" encoding="UTF-8"?>
<playlist version="1" xmlns = "http://xspf.org/ns/0/">
    <trackList>

        <track>
            <location>mp3/07 - Evvariki.mp3</location>
            <title>MP3 Player!</title>         
        </track>

	</trackList>
</playlist>

anybody help plz..

hi

i need to create .xml file by using php dynamically...
i want the below formate...here .mp3 files from url(get parameter).....

<?xml version="1.0" encoding="UTF-8"?>
<playlist version="1" xmlns = "http://xspf.org/ns/0/">
    <trackList>

        <track>
            <location>mp3/07 - Evvariki.mp3</location>
            <title>MP3 Player!</title>         
        </track>

	</trackList>
</playlist>

anybody help plz..

header("Content-Type:application/rss+xml");
        echo "<?xml version=\"1.0\"?>
            <rss version=\"2.0\">

<playlist version=\"1\" xmlns ="http://xspf.org/ns/0/">
    <trackList>

        <track>
            <location>mp3/07 - Evvariki.mp3</location>
            <title>MP3 Player!</title>         
        </track>

	</trackList>
</playlist>";

try this once. i am not test this code

header("Content-Type:application/rss+xml");
echo "<?xml version=\"1.0\"?>
<rss version=\"2.0\">

<playlist version=\"1\" xmlns ="http://xspf.org/ns/0/">
<trackList>

<track>
<location>mp3/07 - Evvariki.mp3</location>
<title>MP3 Player!</title>
</track>

</trackList>
</playlist>";
try this once. i am not test this code

hi rajabhaskar...

i m sorry...this is not wat i want...this is my fault..my explanation was not good...

basically my requirement is when i select 4/5 songs dynamically from my web page..all songs should be stored in my xml file....


anybody solve this one plz...

Simple XML ?

Hi frnds...

I tried my level best..but i got an error..here i want to create tempory xml file..this is the error...

XML Parsing Error: junk after document element
Location: http://www.aaa.com/music/playtrack.php?playlist=06.O.Manasa.mp3.mp3|06.O.Manasa.mp3.mp3
Line Number 2, Column 1:

code....

<?php
$playlist= $_GET['playlist'];
$xmldoc  = "playlist.xml"; 
	//first make sure that no other file with that name exists 
	if(!file_exists($xmldoc)){  
	//try to open the file 
	if($fp=fopen($xmldoc,'w+')){ 
	//write to the file 
	fwrite($fp,"<?xml version='1.0' ?>"); 
$songs=explode('|',$playlist);
header("Content-type: text/xml");

echo "<trackList>";
foreach ( $songs  as $key=>$value){
echo "<track>";
    echo "<location>".$value."</location>";
echo "</track>";
 }
echo "</trackList>";
}}
?>

plz change this as correctly...

thanks in advance...

<? $playlist= $_GET['playlist'];
$xmldoc = "playlist.xml";
//first make sure that no other file with that name exists
if(!file_exists($xmldoc)){
//try to open the file
if($fp=fopen($xmldoc,'w+')){
//write to the file
fwrite($fp,"<?xml version='1.0' ?>");
//$playlist="06.O.Manasa.mp3|06.O.Manasa.mp3";
$songs=explode('|',$playlist);
//header("Content-type: text/xml");
fwrite($fp,"<trackList>");
foreach ( $songs as $key=>$value)
{
$wxml="
<track>
 <location>".$value."</location>
  </track>";
  fwrite($fp,$wxml);
  }
fwrite($fp,"</trackList>");
}}
 ?>

try like this.

The easiest way would be to use XmlWriter lib, put your data in an assoc arrray (in this example $data) and use code below

$xml = new XmlWriter();
$xml->openMemory();
$xml->startDocument('1.0', 'UTF-8');
$xml->startElement('root');
write($xml, $data);
$xml->endElement();
echo $xml->outputMemory(true);

function write(XMLWriter $xml, $data) {
  foreach($data as $key => $value) {
    if(is_array($value)) {
      $xml->startElement($key);
      write($xml, $value);
      $xml->endElement();
      continue;
    }
    $xml->writeElement($key, $value);
  }
}
<? $playlist= $_GET['playlist'];
$xmldoc = "playlist.xml";
//first make sure that no other file with that name exists
if(!file_exists($xmldoc)){
//try to open the file
if($fp=fopen($xmldoc,'w+')){
//write to the file
fwrite($fp,"<?xml version='1.0' ?>");
//$playlist="06.O.Manasa.mp3|06.O.Manasa.mp3";
$songs=explode('|',$playlist);
//header("Content-type: text/xml");
fwrite($fp,"<trackList>");
foreach ( $songs as $key=>$value)
{
$wxml="
<track>
 <location>".$value."</location>
  </track>";
  fwrite($fp,$wxml);
  }
fwrite($fp,"</trackList>");
}}
 ?>

try like this.

Hi ..


this is working fine....
here i m getting another problem...
one user creating the xml file in the web, at the same time another user trying to create the xml file.it ll not override the previous xml file.....so, it should be availble for multiple users...

i think u r all got my point..plz reply with patience...

Thanks in advance..

<? $playlist= $_GET['playlist'];
$xmldoc = "playlist.xml";
//first make sure that no other file with that name exists
if(!file_exists($xmldoc)){
//try to open the file
if($fp=fopen($xmldoc,'w+')){
//write to the file
fwrite($fp,"<?xml version='1.0' ?>");
//$playlist="06.O.Manasa.mp3|06.O.Manasa.mp3";
$songs=explode('|',$playlist);
//header("Content-type: text/xml");
fwrite($fp,"<trackList>");
foreach ( $songs as $key=>$value)
{
$wxml="
<track>
 <location>".$value."</location>
  </track>";
  fwrite($fp,$wxml);
  }
fwrite($fp,"</trackList>");
}}
 ?>

try like this.

hi sir...


sorry 4 the previous post..
here it is working fine..but i m getting another problem...

by using the above code..i m getting the below result...

<?xml version="1.0" ?> 
- <trackList>
- <track>
  <location>demo2.mp3</location> 
  </track>
  </trackList>

but i want to add the play list to the same code...i want the below output...

<?xml version="1.0" encoding="UTF-8" ?> 
- <playlist version="1" xmlns="http://xspf.org/ns/0/">
- <trackList>
- <track>
  <location>demo2.mp3</location> 
 
  </track>
  </trackList>
  </playlist>

plz reply with patience...

<? $playlist= $_GET['playlist'];
$xmldoc = "playlist.xml";
//first make sure that no other file with that name exists
if(!file_exists($xmldoc)){
//try to open the file
if($fp=fopen($xmldoc,'w+')){
//write to the file
fwrite($fp,"<?xml version='1.0' ?>");
//$playlist="06.O.Manasa.mp3|06.O.Manasa.mp3";
$songs=explode('|',$playlist);
//header("Content-type: text/xml");
fwrite($fp,"<trackList>");
foreach ( $songs as $key=>$value)
{
$wxml="
<track>
 <location>".$value."</location>
  </track>";
  fwrite($fp,$wxml);
  }
fwrite($fp,"</trackList>");
}

}
else
{
if($fp=fopen($xmldoc,'w+')){
//write to the file
fwrite($fp,"<?xml version='1.0' ?>");
//$playlist="06.O.Manasa1.mp3|06.O.Manasa1.mp3";
$songs=explode('|',$playlist);
//header("Content-type: text/xml");
fwrite($fp,"<trackList>");
foreach ( $songs as $key=>$value)
{
$wxml="
<track>
 <location>".$value."</location>
  </track>";
  fwrite($fp,$wxml);
  }
fwrite($fp,"</trackList>");
}
}
 ?>

hi , actually i am not understood ur point. the above code says that if playinglist.xml is already exists override the previous xml file. see once.

<?  $playlist= $_GET['playlist'];
$xmldoc = "playlist.xml";
//first make sure that no other file with that name exists
if(!file_exists($xmldoc)){
//try to open the file
if($fp=fopen($xmldoc,'w+')){
//write to the file
fwrite($fp,"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
//$playlist="06.O.Manasa.mp3|06.O.Manasa.mp3";
$songs=explode('|',$playlist);
//header("Content-type: text/xml");
fwrite($fp,"<playlist version=\"1\" xmlns=\"http://xspf.org/ns/0/\">
<trackList>");
foreach ( $songs as $key=>$value)
{
$wxml="
<track>
 <location>".$value."</location>
 <title>MP3 Player!</title>
  </track>";
  fwrite($fp,$wxml);
  }
fwrite($fp,"</trackList>
 </playlist>");
}

}
else
{
if($fp=fopen($xmldoc,'w+')){
//write to the file
fwrite($fp,"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
//$playlist="06.O.Manasa1.mp3|06.O.Manasa1.mp3";
$songs=explode('|',$playlist);
//header("Content-type: text/xml");
fwrite($fp,"<playlist version=\"1\" xmlns=\"http://xspf.org/ns/0/\">
<trackList>");
foreach ( $songs as $key=>$value)
{
$wxml="
<track>
 <location>".$value."</location>
 <title>MP3 Player!</title>
  </track>";
  fwrite($fp,$wxml);
  }
fwrite($fp,"</trackList>
 </playlist>");
}
}
 ?>

try like this.

<?  $playlist= $_GET['playlist'];
$xmldoc = "playlist.xml";
//first make sure that no other file with that name exists
if(!file_exists($xmldoc)){
//try to open the file
if($fp=fopen($xmldoc,'w+')){
//write to the file
fwrite($fp,"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
//$playlist="06.O.Manasa.mp3|06.O.Manasa.mp3";
$songs=explode('|',$playlist);
//header("Content-type: text/xml");
fwrite($fp,"<playlist version=\"1\" xmlns=\"http://xspf.org/ns/0/\">
<trackList>");
foreach ( $songs as $key=>$value)
{
$wxml="
<track>
 <location>".$value."</location>
 <title>MP3 Player!</title>
  </track>";
  fwrite($fp,$wxml);
  }
fwrite($fp,"</trackList>
 </playlist>");
}

}
else
{
if($fp=fopen($xmldoc,'w+')){
//write to the file
fwrite($fp,"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
//$playlist="06.O.Manasa1.mp3|06.O.Manasa1.mp3";
$songs=explode('|',$playlist);
//header("Content-type: text/xml");
fwrite($fp,"<playlist version=\"1\" xmlns=\"http://xspf.org/ns/0/\">
<trackList>");
foreach ( $songs as $key=>$value)
{
$wxml="
<track>
 <location>".$value."</location>
 <title>MP3 Player!</title>
  </track>";
  fwrite($fp,$wxml);
  }
fwrite($fp,"</trackList>
 </playlist>");
}
}
 ?>

try like this.

Hi sir,

thanks 4 ur reply..its working fine...

but xml file is not override(updating)...it is same as first time creation of xml file...

<?  $playlist= $_GET['playlist'];
$xmldoc = "playlist.xml";
//first make sure that no other file with that name exists
if(!file_exists($xmldoc)){
//try to open the file
if($fp=fopen($xmldoc,'w+')){
//write to the file
fwrite($fp,"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
//$playlist="06.O.Manasa.mp3|06.O.Manasa.mp3";
$songs=explode('|',$playlist);
//header("Content-type: text/xml");
fwrite($fp,"<playlist version=\"1\" xmlns=\"http://xspf.org/ns/0/\">
<trackList>");
foreach ( $songs as $key=>$value)
{
$wxml="
<track>
 <location>".$value."</location>
 <title>MP3 Player!</title>
  </track>";
  fwrite($fp,$wxml);
  }
fwrite($fp,"</trackList>
 </playlist>");
}

}
else
{
if($fp=fopen($xmldoc,'w+')){
//write to the file
fwrite($fp,"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
//$playlist="06.O.Manasa1.mp3|06.O.Manasa1.mp3";
$songs=explode('|',$playlist);
//header("Content-type: text/xml");
fwrite($fp,"<playlist version=\"1\" xmlns=\"http://xspf.org/ns/0/\">
<trackList>");
foreach ( $songs as $key=>$value)
{
$wxml="
<track>
 <location>".$value."</location>
 <title>MP3 Player!</title>
  </track>";
  fwrite($fp,$wxml);
  }
fwrite($fp,"</trackList>
 </playlist>");
}
}
 ?>

try like this.

Hi Sir,


Finally i got ur point...

Thanks a lot...now my problem solved...

Thanks once again...

it is working fine for me. keep track of ur code (else
part).