Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML struture question

Status
Not open for further replies.

gilly30

Programmer
Dec 16, 2009
2
GB
Hello Id be gratefull for any help at all

I have created a flash mp3 player and i am trying to run it from a generated XML file. The file is being created fine however not in the xml formate i would like - I need the below structure

<?xml version="1.0" encoding="iso-8859-1"?>
<songs>

<song atitle="Beastie Boys" aurl="17-beastie_boys-3_mcs_and_1_dj-apc-2000.mp3"/>

<song atitle="PM DAWN" aurl="413_-_VA_-_P.M._Dawn_-_Set_Adrift_On_Memory_Bliss.mp3"/>

</songs>

But when i retrive my file it comes out like so

<?xml version="1.0"?><songs><song_atitle>PM DAWN</song_atitle><aurl>413_-_VA_-_P.M._Dawn_-_Set_Adrift_On_Memory_Bliss.mp3</aurl><song_atitle>sCOTT</song_atitle><aurl>17-beastie_boys-3_mcs_and_1_dj-apc-2000.mp3</aurl>

How do i structure Songs songtitle aurl? Please help its driving my nuts!!
 
It looks as though you have XSLT somewhere in the process that is trying to convert your song attributes to individual tags. The XSLT is not working properly. It should be producing something like this:
Code:
<?xml version="1.0"?>
  <songs>
    <song>
      <atitle>PM DAWN<atitle>
      <aurl>413_-_VA_-_P.M._Dawn_-_Set_Adrift_On_Memory_Bliss.mp3</aurl>
    </song>
    <song>
      <atitle>Beastie Boys</atitle>
      <aurl>17-beastie_boys-3_mcs_and_1_dj-apc-2000.mp3</aurl>
    </song>
  </songs>
Format is for readability, otherwise irrelevant. I haven't a clue where sCOTT came from.
 
Hello

Im creating the file from an SQL database

below is the code I have creating the xml file above

<?php// set server access variables include ("connection.php"); // create query $query = "SELECT * FROM songs"; // execute query $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); // see if any rows were returned if (mysql_num_rows($result) > 0) { // yes //Top of xml file $_xml = '<?xml version="1.0"?>'; $_xml .="<songs>"; while($row = mysql_fetch_array($result)) { $_xml .="<song_atitle>".$row['Name']."</song_atitle>"; $_xml .="<aurl>".$row['file']."</aurl>"; } $_xml .="</songs>"; //Output the xml string print $_xml; // Could also write to a file at this point file_put_contents("./songs/song.xml", $_xml); // } else { // no // print status message echo "No rows found!"; } ?>
 
 http://dj-info.netai.net/playlistcreate.php
You should ask in the PHP forum, should be pretty simple, something like

Code:
$_xml .="<song> atitle='".$row['Name']."</song_atitle>";

but I have no idea of PHP

Cheers,
Dian
 
[tt]$_xml="songs\n";
while($row = mysql_fetch_array($result)) {
$_xml .='<song atitle="'.$row['Name'].'" aurl="'.$row['file'].'" />'."\n";
}
$_xml .="</songs>";[/tt]

ps:
[1] You sure can ask the question in this xml forum. Subjects may vary --- some more closely some more remotely related to core xml technologies, but the division of labour is not yet evolved to such a degree, industrial-wide or restricted to this site alone, to warrant... you know what I would say.
[2] But competence varies. I, as a long time xml forum contributor, know somewhat who-is-who, their competence, amongst contributors. If I know a subject mostly likely, after a reasonable time delay, could not get an adequate care, I would redirect poster to other related forums.
[3] It is at all time imperative to pose "good" question with sufficient data for members to deliberate. "Bad" questions, no matter how closely related to xml, are better re-directed to dust-bins.
 
Upon re-reading what I posted, I find I had a typo here.
[tt] $_xml="[red]<[/red]songs[red]>[/red]\n";[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top