Jump to content

[SOLVED] Can I use PHP to output a XML file?


polemios

Recommended Posts

I know this has been asked before and I have read several threads elsewhere that sort of cover the topic, but nothing is helping me.

 

Briefly, here's the issue:

I have made a flash file that parses an XML file to get its content. I've tested it with a static XML and it works great. Let's call that XML "xml1".

I have made a MYSQL db and the accompanying PHP files to dynamically add information to the database. This works great.

I tried to use PHP to output an XML file to replace the static one, thus completing the circle and allowing the client to enter data into the db and see it in flash. Let's call this one "xml2".

 

The flash file won't accept the data from "xml2". I assume it's in some sort of doctype issue.

By the way, I thought it might be the fact that the extension of "xml2" is .php instead of .xml, but that doesn't matter. "xml1" was successfully tested with a .php extension.

 

When I view "xml2" in a browser, it looks like it's being treated like html instead of XML, but when I view the source, it looks exactly like the code from "xml1". What is the difference?

 

Here's the code for "xml2", the problematic one:

<?php

print "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>" .
	"\n<diary>";

require "./includes/db.php";
require "./includes/functions.php";
require "./includes/authentication.php";

//Connect to server
if (!($connection = @ mysql_connect($hostName, $username, $password)))
showerror();

if (!mysql_select_db($databaseName, $connection))
showerror();

//Run a query to pull in the names, to use in the following list
			$query="SELECT entry_id, entry_date, entry_month, entry_year, entry_day, entry_words, entry_img_url FROM diary_entries ORDER BY entry_year DESC, entry_month DESC, entry_date DESC";

			if (!($result = @ mysql_query ($query, $connection)))
			showerror();

			while ($row = @ mysql_fetch_row($result))
			{
				print "\n<entry>" .
				"\n\t<date>{$row[1]}</date>".
				"\n\t<month>";
				monthNumberToName($row[2]);
				print "</month>" .
				"\n\t<day>{$row[4]}</day>".
				"\n\t<words>";
				formatXML($row[5]);
				print "</words>" .
				"\n\t<img>{$row[6]}</img>" .
				"\n</entry>";
			}
print "\n</diary>";
?>

 

Here's "xml1"; what "xml2" should replicate in a dynamic setting:

 

<?xml version="1.0" encoding="iso-8859-1"?>
<diary>
<entry>
	<date>10</date>
	<month>September</month>
	<day>Saturday</day>
	<words>Blah Blah Blah</words>
	<img>./Images/Diary/whistle.jpg</img>
</entry>
</diary>

 

Any ideas?

Thanks

Link to comment
Share on other sites

It may be that the script is not making it through the PHP parser.  I'm not sure how it works when a flash application opens a file, but if the request isn't handled by Apache, the flash application will just get the raw PHP code and choke.  I don't know Flash, but I imagine there's a way to invoke PHP, even if it has to be something as kludgy as executing a shell command.

Link to comment
Share on other sites

But only if it's being delivered to the Flash application by Apache.  If the Flash application is simply grabbing the file off the hard drive, the script never goes through the PHP parser.

 

Instead of trying to process the file, simply output it as text within your Flash application.  This will tell you whether the PHP is actually being interpreted or not.

Link to comment
Share on other sites

But only if it's being delivered to the Flash application by Apache.  If the Flash application is simply grabbing the file off the hard drive, the script never goes through the PHP parser.

 

Instead of trying to process the file, simply output it as text within your Flash application.  This will tell you whether the PHP is actually being interpreted or not.

Flash is not a server based language.. and therefore the only way to fetch a file would be a request to the server for the file.. in the same way you request the file when you use you browser. it will be delievered by apache when you request the file, because flash has no access to get the file any other way..

Link to comment
Share on other sites

Well, it seems that the content type addition helped the browser display it as an XML. It appears to be perfect. But for some reason, Flash still isn't getting the info from it. It reads in a browser and in it's source exactly like "xml1". I know this isn't an actionscript forum, so i won't bore people. I wonder why it still isn't loading it. I can only assume it's in the PHP to XML process since the identical "xml1" loads fine.

 

Wierd.

Link to comment
Share on other sites

I'm using Flash's built in XML object.

 

I then use actionscript to parse the XML into usable variables for my application.

It really baffles me. Right now, thanks to your help, the two XML files behave identically. Except that one gets parsed into Flash and the other doesn't.

 

I think I'll move this discussion to actionscript.org. Maybe.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.