Jump to content

Updating and accessing XML file


hpnut4ever

Recommended Posts

Hello all,

 

This seems kind of complicated, so I'll explain as best I can.

 

I have a PHP document that can successfully save an external XML file.  I need to be able to update that XML file whenever I view the profile page of the site I'm working on, because this XML file is being loaded into a Flash music player on the profile page.

 

Is there a way to update the XML from the profile page's code?  I know that I can't just stick the code I've used to create the document in, or else I'll get an error telling me that I cannot set the header or something similar.

 

Here is the code I have for creating the XML, if it will be of any help.

 

$bid = $_GET['bid'];
if(!isset($bid)){
$bid = 3;
}

// create document type
$dom = new DOMDocument("1.0");

// display document as plain text
header("Content-Type: text/plain");


$query = "SELECT * FROM bands WHERE id = '$bid'";
$result = mysql_query($query);

$squery = "SELECT * FROM songs WHERE artist_id = '$bid'";
$sresult = mysql_query($squery);


$root = $dom->createElement("tracklist");
	$dom->appendChild($root);


while($artist = mysql_fetch_array($result)){
while($song = mysql_fetch_array($sresult)){

	$track = $dom->createElement("track");
	$root->appendChild($track);

		$item = $dom->createElement("song");
		$track->appendChild($item);

			$namevalue = $dom->createTextNode($song['title']);
			$item->appendChild($namevalue);

		$item = $dom->createElement("artist");
		$track->appendChild($item);

			$namevalue = $dom->createTextNode($artist['name']);
			$item->appendChild($namevalue);

		$item = $dom->createElement("file");
		$track->appendChild($item);

			$namevalue = $dom->createTextNode("media/file_".$song['id']);
			$item->appendChild($namevalue);

		$item = $dom->createElement("ext");
		$track->appendChild($item);

			$namevalue = $dom->createTextNode($song['file_ext']);
			$item->appendChild($namevalue);
}
}


// save and display XML tree
$dom->save("php-xml.xml");

 

Any help or suggestions would be greatly appreciated!

Link to comment
https://forums.phpfreaks.com/topic/173737-updating-and-accessing-xml-file/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.