eswar.aspire 0 Newbie Poster

Hello,

I getting an error when generating an XML from php and couldn’t find any duplicate root element or space in my XML document. After generating an XML document, it should be saved in specified directory get from POST variable.

Error Details:

Only one top level element is allowed in an XML document. Error processing resource 'http://localhost/music24/XML_GENERATE....
<b>Notice</b>:  Undefined variable: POST in <b>C:\wamp\www\music24\XML_GENERATE.php</b> on line <...

Message: Only one top level element is allowed in an XML document.

URI: http://localhost/music24/XML_GENERATE.php

My Php code:

<?php
$path_to_image_dir = $POST['PATH_name_SONG']; 
//$path_to_image_dir = "images";
$xml_string = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<songs> 
</songs>
XML;

$xml_generator = new SimpleXMLElement($xml_string);

if ( $handle = opendir( $path_to_image_dir ) ) 
{
    while (false !== ($file = readdir($handle))) 
    {
        if ( is_file($path_to_image_dir.'/'.$file) ) 
        {

 $file_name=explode_dir($file);
 $folder_name=innermostdir($path_to_image_dir);
           $image = $xml_generator->addChild('song');  
           $image->addChild('track', $file_name);    
           $image->addChild('artist', $folder_name); 
           $image->addChild('url', $path_to_image_dir.'/'.$file);    
        }
    }
    closedir($handle);
}

function innermostdir($path)

{
$inner_dir=basename(rtrim($path,'/'));
return $inner_dir;

}
 function explode_dir($file)

 {
$info = pathinfo($file);
$filename =  basename($file,'.'.$info['extension']);

 return $filename;
 }


 $folder_name=innermostdir($path_to_image_dir);

//$xml_generator->formatOutput=true;

header("Content-Type: text/xml");
echo $xml_generator->asXML();   

$xml_generator->asXML($path_to_image_dir."/".$folder_name.".xml");

//header("location: login1/Admin.php");
//exit();
?>

My Xml document:

<?xml version="1.0" encoding="UTF-8" ?> 
-<songs>
- <song>
  <track>background</track> 
  <artist>images</artist> 
  <url>images/background.png</url> 
  </song>
- <song>
  <track>background2_06</track> 
  <artist>images</artist> 
  <url>images/background2_06.png</url> 
  </song>
- <song>
  <track>text_image1</track> 
  <artist>images</artist> 
  <url>images/text_image1.png</url> 
  </song>
  </songs>

Any help or suggestion..I don’t know why I am getting this error..I am new to PHP.
Thanks in adavance,
Eswaran Saravanan,
University west,
Sweden.