0

I am saving my dom xml file with

`<?php
if(isset($_POST["song"])&& $_POST['song'] != "") 
    {
        $song = $_POST["song"];
    }
    else {$song=array();} 

$dom = new DOMDocument("1.0");
// display document in browser as plain text 
// for readability purposes

// create root element
$root = $dom->createElement("playlist");
$dom->appendChild($root);
$root->setAttribute('version', "1");
$root->setAttribute('xmlns', "http://xspf.org/ns/0/");
$rootnext = $dom->createElement("trackList");
$root->appendChild($rootnext);
foreach ($song as $counter) {
    $tokens = ",";
    $tokenized = strtok($counter, $tokens);
// create child element

$song = $dom->createElement("track");
$rootnext->appendChild($song);
$song1 = $dom->createElement("creator");
$song->appendChild($song1);
$text = $dom->createTextNode("www.indiantags.com");
$song1->appendChild($text); 
$song1 = $dom->createElement("title");
$song->appendChild($song1);
// create text node
$text = $dom->createTextNode($tokenized);
$song1->appendChild($text); 
$tokenized = strtok($tokens);
$song1 = $dom->createElement("location");
$song->appendChild($song1);
$text = $dom->createTextNode($tokenized);
$song1->appendChild($text); 

}

// save 
$dom->save("playlist.xml");

?>
<object data="42-mp3player.swf?autostart=true&playlist=playlist.xml" type="application/x-shockwave-flash" width="400" height="300"><param name="movie" value="42-mp3player.swf?autostart=true&playlist=playlist.xml"/></object>

`

But all I need is I want to save this playlist.xml file with dynamic name some thing with microtime function or else sessionid name ..any body would like to throw some light on it?

Thank you

Sam
  • 1,509
  • 3
  • 19
  • 28

2 Answers2

0

IXMLDOMDocument2 interface has a save method. Check this.

fr21
  • 1,746
  • 7
  • 26
  • 45
  • I guess, sai uses PHP. So IXMLDOMDocument2 will probably not work. – Boldewyn Nov 16 '09 at 08:08
  • i am using php ...this will not work in php ...anybody can help – user2273164 Nov 16 '09 at 12:38
  • hi pavan, i have added my code ...all i need is at runtime i need to get the dynamic name to the file instead of playlist.xml ....i am novice in xml apart from few tags i dont know much about xml...your help is appreciated...Thank you – user2273164 Nov 16 '09 at 13:30
0

To save with a dynamic name, you can do something like this in PHP:

//Set dynamic name - used microtime in this example but you could change this
//to another dynamic naming scheme
$dynamicPlaylistName = microtime();

//Save XML with dynamic name
$dom->save($dynamicPlaylistName.'.xml');

The code above sets dynamicPlaylistName to whatever you put after the equals sign on that line, and then saves the xml with the value of dynamicPlaylistName as its file name with '.xml' appended to it.

If you also want the XML file to be formatted with indents and nesting, see my answer to this question. Note that you would likely only need to add the following two lines somewhere prior to saving the XML to get formatting in your case:

$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
Community
  • 1
  • 1
Witman
  • 1,488
  • 2
  • 15
  • 19