Modify existing XML file with this PHP script

Hello All, I have been working with this file to manipulate an xml doucment as part of a CMS. The trouble I am having is that it formats the xml in a way that when the flash file reads it, its not reading properly. It exports as


<songs><song title="On Mercury" artist="Red Hot Chili Peppers" path="/red-hot-chili-peppers/on-mercury.mp3" /><song title="Universally Speaking" artist="Red Hot Chili Peppers" path=" /red-hot-chili-peppers/universally-speaking.mp3" /></songs>

and I need it to export as

<portfolio> 
<picture image="thumbnails/rings/400/96-00022.jpg" thumb="thumbnails/rings/70/96-00022.jpg" captiontx="White Gold Diamond Daisies Ring 1.05ct.t.w. 18k  $913751.00" hover="96-00022"/></portfolio>

Basically = and =

I have changed everything as had it working like I wanted, however when you added a new node, it erased the previous one and placed the new one there.

Thanks in advance

Here is the code:
index.php


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Add Songs</title>
<style type="text/css">
table {
 border:1px dotted #ccc;
 width:100%;
}
td {
  background-color:#aaa;
 color:#fff;
}
fieldset { border:0; }
label { margin-right:5px; }
</style>
</head>
<body>
<form action="processForm.php" method="post">
<fieldset>
<label for="name">Name:</label> <input type="text" id="name" name="name"/><br />
<label for="artist">Artist:</label><input type="text" id="artist" name="artist" /><br />
<label for="path">Path:</label> <input type="text" id="path" name="path" /> <br />
<select name="action">
<option value="ins">Insert</option>
<option value="del">Delete</option>
</select>
<input type="submit" />
</fieldset>
</form>
<p>Current entries:</p>
<?php
function start_tag($parser, $name, $attrs){
 global $table_string;
 $table_string .= "<tr><td>$attrs[title]</td><td>$attrs[artist]</td><td>$attrs[path]</td></tr>";
}
function end_tag($parser, $name){}
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_set_element_handler($parser, "start_tag", "end_tag");
$table_string = "<table>
  <tr><th>Title</th><th>Artist</th><th>Path</th></tr>";
xml_parse($parser, file_get_contents("playlist.xml")) or die("Error parsing XML file");
$table_string .= "</table>";
echo $table_string;
?>
</body>
</html>

processForm.php


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Adding Songs...</title>
<style type="text/css">
em {
 text-align:center;
}
</style>
</head>
<body>
<p>
<?
$songs = Array();
function start_element($parser, $name, $attrs){
 global $songs;
 if($name == "song"){
  array_push($songs, $attrs);
 }
}
function end_element ($parser, $name){}
$playlist_string = file_get_contents("playlist.xml");
$parser = xml_parser_create();
xml_set_element_handler($parser, "start_element", "end_element");
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parse($parser, $playlist_string) or die("Error parsing XML document.");
print "<br />";
if($_POST['action'] == "ins"){
 array_push($songs, Array(
    "title" => $_POST['name'],
    "artist" => $_POST['artist'],
    "path" => $_POST['path']));
 $songs_final = $songs;
}else if($_POST['action'] == "del"){
 $songs_final = Array();
 foreach($songs as $song){
  if($song['title'] != $_POST['name']){
   array_push($songs_final, $song);
  }
 }
}
$write_string = "<songs>";
foreach($songs_final as $song){
 $write_string .= "<song title=\"$song[title]\" artist=\"$song[artist]\" path=\"$song[path]\" />";
}
$write_string .= "</songs>";
$fp = fopen("playlist.xml", "w+");
fwrite($fp, $write_string) or die("Error writing to file");
fclose($fp);
print "<em>Song inserted or deleted successfully :)</em><br />";
print "<a href=\"index.php\" title=\"return\">Return</a>";
?>
</p>
</body>
</html>
 

playlist.xml


<songs><song title="On Mercury" artist="Red Hot Chili Peppers" path="/red-hot-chili-peppers/on-mercury.mp3" /><song title="Universally Speaking" artist="Red Hot Chili Peppers" path=" /red-hot-chili-peppers/universally-speaking.mp3" /></songs>