Some XML help

Associate
Joined
13 Nov 2003
Posts
1,567
Location
Manchester
Hi Guys

Working on creating a database driven xml feed for a flash application.

I can out output the data in a valid xml format using the following

Code:
 $_xml .="\t<song title=\"" . $row["TitleOfTrack"] . "\">\r\n";
 $_xml .="\t\t<artist>Nicksy</artist>\r\n";
 $_xml .="\t\t<src>" . $row["FilenameOfTrack"] . "</src>\r\n";
$_xml .="\t</song>\r\n";

Which gives me

Code:
	<playlist>
−
	<song title="Nicksy's Cottage Chat">
<artist>Nicksy</artist>
<src>radio-show/NicksysCottageChatJULY_1.mp3</src>
</song>
−
	<song title="Nicksy's Cottage Chat">
<artist>Nicksy</artist>
<src>radio-show/NicksysCottageChatJULY.mp3</src>
</song>
−
	<song title="Nicksy's Cottage Chat June16th">
<artist>Nicksy</artist>
<src>radio-show/CottageChat16thJUneMP3.mp3</src>
</song>
−
	<song title="Cottage Chat June3rd">
<artist>Nicksy</artist>
<src>radio-show/CottageChatJune3rd.mp3</src>
</song>
−
	<song title="Cottage Chat June 2">
<artist>Nicksy</artist>
<src>radio-show/CottageChatJuneWeek2.mp3</src>
</song>
−
	<song title="Cottage Chat June">
<artist>Nicksy</artist>
<src>radio-show/CottageChatJUNEMP3.mp3</src>
</song>
−
	<song title="Week 2">
<artist>Nicksy</artist>
<src>radio-show/CottageChatFINALmix.mp3</src>
</song>
−
	<song title="Week 1">
<artist>Nicksy</artist>
<src>CottageChatWeek1.mp3</src>
</song>
</playlist>

However, the flash app needs the xml to look more like this

Code:
<playlist>
<song title="songtitle" artist="artist" src="filenameoftrack" />
</playlist>

How would I modify the code above to achieve this. Im fairly certain its not valid XML, but it seems to be the way the flash app wants it, and I have no control over that.

Thanks
Aaron
 
It looks valid to me,
I reckon you could do something like this to get it to work:

Code:
$_xml .= "<playlist>";
$_xml .="\t<song title=\"" . $row["TitleOfTrack"] . "\" artist=Nicksy src=\"". $row["FilenameOfTrack"] . "\" />\r\n";
$_xml .= "</playlist>";

There might be one or two typos in there but you should get the idea i hope!
 
That would create a new <playlist> for each file--are you sure that's what you want?

This would certainly be more logical:

PHP:
<?php
$result = mysql_query("SELECT * FROM songs");
?>
<playlist>
<?php while ( $row = mysql_fetch_array($result) ) : ?>
    <song title="<?php echo $row["TitleOfTrack"] ?>" artist="Nicksy" src="<?php echo $row["FilenameOfTrack"] ?>" />
<?php endwhile; ?>
</playlist>
 
Back
Top Bottom