INSERTING INFORMATION INTO XML FILE
Posted: Sat Mar 19, 2011 10:55 pm
Hey guys,
I am trying to insert data into an xml file each time an if() function is triggered. Here is the xml file
<?xml version="1.0"?>
<playlist version="1">
<trackList>
<track>
<location>members/1/test1.mp3</location>
<artist>test</artist>
<title>test</title>
</track>
<track>
<location>members/1/tu_presencia</location>
<artist>Alex Zurdo</artist>
<title>Tu Presencia</title>
</track>
<track>
<location>members/1/03 - agradecerte</location>
<artist>Alex Zurdo</artist>
<title>Agradecerte</title>
</track>
</trackList>
</playlist>
and here is the php file to insert new information.
<?php
$mid = mysql_insert_id();
$mq = mysql_query("SELECT * FROM updates WHERE userid='".$userid."' AND id='".$mid."'");
$mrow = mysql_fetch_assoc($mq);
$mpath = $mrow['musicpath'];
$filename = "/var/www/members/1/playlist.xml";
$xml = simplexml_load_file($filename);
$sxe = new SimpleXMLElement($xml->asXML());
$track = $sxe->addChild("track");
$track->addChild("location", "test");
$track->addChild("title", "test");
echo "<br />";
$sxe->asXML("/var/www/members/1/playlist.xml");
?>
now I have the insertion working fine, however, it inserts the information between the closing </tracklist> and </playlist> tags. Which renders the information useless. I need to get the dynamic information to be inserted before the </tracklist> tag and the </playlist> in order to use the information. Any suggestions?
I am trying to insert data into an xml file each time an if() function is triggered. Here is the xml file
<?xml version="1.0"?>
<playlist version="1">
<trackList>
<track>
<location>members/1/test1.mp3</location>
<artist>test</artist>
<title>test</title>
</track>
<track>
<location>members/1/tu_presencia</location>
<artist>Alex Zurdo</artist>
<title>Tu Presencia</title>
</track>
<track>
<location>members/1/03 - agradecerte</location>
<artist>Alex Zurdo</artist>
<title>Agradecerte</title>
</track>
</trackList>
</playlist>
and here is the php file to insert new information.
<?php
$mid = mysql_insert_id();
$mq = mysql_query("SELECT * FROM updates WHERE userid='".$userid."' AND id='".$mid."'");
$mrow = mysql_fetch_assoc($mq);
$mpath = $mrow['musicpath'];
$filename = "/var/www/members/1/playlist.xml";
$xml = simplexml_load_file($filename);
$sxe = new SimpleXMLElement($xml->asXML());
$track = $sxe->addChild("track");
$track->addChild("location", "test");
$track->addChild("title", "test");
echo "<br />";
$sxe->asXML("/var/www/members/1/playlist.xml");
?>
now I have the insertion working fine, however, it inserts the information between the closing </tracklist> and </playlist> tags. Which renders the information useless. I need to get the dynamic information to be inserted before the </tracklist> tag and the </playlist> in order to use the information. Any suggestions?