Skip to main content
Inspiring
April 3, 2008
Question

PHP to XML to Flash

  • April 3, 2008
  • 11 replies
  • 2128 views
If I use a XML file it's ok.
If I use a PHP to make a XML it says:
"Error #1088: The markup in the document following the root element must be well-formed."

If I open my PHP in a browser it's rightly showed as XML.
If I save the page source of my PHP from my browser as XML then load it on Flash it's ok.
This topic has been closed for replies.

11 replies

ric_biaAuthor
Inspiring
April 7, 2008
On Localhost I'm still getting the error and I can't understand why.

But I tested online and it's function as it should be (with and without http://).
Damon Edwards
Inspiring
April 7, 2008
When did I ever say he should read the file directly? I said he doesn't need to use the absolute URL to the file, you do know what an absolute URL is, right? wait, before you google it, its the full path, like http://www.path.com/file.ext. I did however say this needs to be tested online. That "do some weird cast to compensate" thing you're talking about, is what will enable him to work with the returned XML data. So, I think you should quickly exit this thread stage right, before you lead the OP down a wild goose chase. Actually, I'll step away, this thread is going nowhere.
Inspiring
April 7, 2008
since errors that are claimed to be fact need to be corrected on a tech group, for credibility of the group, here goes:

quote:

Originally posted by: dzedward
When did I ever say he should read the file directly?

by continually insisting that he read the source, then try to format that into XML data with some weird cast. And btw, it's not actually casting (but that was the word you used).
quote:


I said he doesn't need to use the absolute URL to the file, you do know what an absolute URL is, right?


yes, I think that I just might know :) but I don't think that you actually do
quote:


wait, before you google it, its the full path, like http://www.path.com/file.ext.


no, the terms "full path" and "absolute URL" are not synonymous, like you think they are. E.g., the URL has a hostname and a protocol
quote:


I did however say this needs to be tested online.


which it doesn't. He'd already said that he has run intermittent successful tests locally.
quote:


That "do some weird cast to compensate" thing you're talking about, is what will enable him to work with the returned XML data.


no, he already said that had read the data correctly. Now he needs to determine the cause of the intermittent failure.
quote:


So, I think you should quickly exit this thread stage right, before you lead the OP down a wild goose chase. Actually, I'll step away, this thread is going nowhere.

have a nice day, no offense is intended to you

(but I'm wondering if you're aware that a person can run a webserver with php on their local computer, and access it with http://localhost as an example. Maybe that's the source of your confusion.)
Inspiring
April 7, 2008
so you think he should read the file directly, do some weird cast to compensate for doing it wrong in the first place - and things are supposed to turn out well?

and if a value supplied by the php script is not explicit, then what does he do? Does casting turn 1 +1 into a 2? Php files are meant to be interpreted. His might even have an include, which also shoots your theory down. Why do it wrong and then kludge it with a weird cast to compensate?

I already gave you the example that proves how your suggestion is wrong. I'll repeat:

<?php
echo 1+1;
?>

Instead of getting emotional, you should re-evaluate your approach. The OP himself knows that getting back the php source is just plain wrong. The point of a tech group is to get at the correct answer.

and btw, only testing remotely is a great waste of time.
Damon Edwards
Inspiring
April 7, 2008
"you need to load it as http://etc"

that is not the solution to this problem. all this "new URLRequest("MYFILE.php");" is saying is that the php file to load is in the same directory as the SWF making the call.

"But I said that the trace returns ALL the code in the php ( from "<?php" to "?>" ) not only the XML."

Of course it will, because that is all the data in that file. Casting the returned data to XML will fix that problem. And yes, you should be testing this online, not locally, unless you've allowed the directory this file is in permission to access the internet.
Inspiring
April 7, 2008
quote:

Originally posted by: dzedward
"you need to load it as http://etc"

that is not the solution to this problem. all this "new URLRequest("MYFILE.php");" is saying is that the php file to load is in the same directory as the SWF making the call.


nope. What it is really doing is loading the php source file as a file on localhost. Which is what he has repeatedly pointed out is occurring.

What he needs to do is to call the php as a web page via the webserver, which gets run through the php module and gets interpreted, and then he reads the OUTPUT of the php page.

quote:


"But I said that the trace returns ALL the code in the php ( from "<?php" to "?>" ) not only the XML."

Of course it will, because that is all the data in that file. Casting the returned data to XML will fix that problem. And yes, you should be testing this online, not locally, unless you've allowed the directory this file is in permission to access the internet.


nope, wrong again. If the php file contains:

<?php
echo 1+1;
?>

he wants to receive:
2

he does not want to receive the php source

Damon Edwards
Inspiring
April 7, 2008
You obviously don't much as3 or any terminology, or you would have interpreted my reply correctly.

"Of course it will, because that is all the data in that file. Casting the returned data to XML will fix that problem."

Means, if s/he casts the returned data as xml, ie, var myXML:XML = new XML(e.target.data);, then it will only return the xml document. by tracing e.target.data, you'll read all the bytes in the php document, hence getting the opening and closing php tags.


"nope. What it is really doing is loading the php source file as a file on localhost. Which is what he has repeatedly pointed out is occurring."

Yes, if s/he is testing this from his/her desktop, then the file will be loaded locally, or using localhost. However, he should be testing this online from the beginning, as I've pointed out. You do not need to use the absolute URL to the PHP file, you may still use MYFILE.php, you just need to test this online.
Inspiring
April 7, 2008
1) Flash wants you to handle the io error. IOW write code to handle the error.

something like:
loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);

then write the handler method to go with it

2) then, *why* you are getting an io error is another matter
ric_biaAuthor
Inspiring
April 7, 2008
quote:

Originally posted by: ntbdy
2) then, *why* you are getting an io error is another matter


Maybe the 127.0.0.1 (local address made by easyphp) could be the problem?
ric_biaAuthor
Inspiring
April 6, 2008
I don't know how is it possible, but without any changes it started to function properly.

Ntbdy got it.
ric_biaAuthor
Inspiring
April 6, 2008
quote:

Originally posted by: ric_bia
I don't know how is it possible, but without any changes it started to function properly.



As it's gone, it's returned...

I'm re-getting the error:
Error #2044: Unhandled ioError:. text=Error #2032: Stream Error.

The URL is like this:
" http://127.0.0.1/a_folder/myfile.php"
Inspiring
April 7, 2008
quote:

Originally posted by: ric_bia
As it's gone, it's returned...

I'm re-getting the error:
Error #2044: Unhandled ioError:. text=Error #2032: Stream Error.

The URL is like this:
" http://127.0.0.1/a_folder/myfile.php"

note that you are getting an IO error, not a Security Error - hence you are not at the point of dealing with any sandbox violation.

I just looked and found a page of responses also saying that the problem comes and goes:
http://www.actionscript.org/forums/showthread.php3?t=138164

Maybe that will give you something useful on how to proceed.
Damon Edwards
Inspiring
April 5, 2008
"trace(event.target.data);"

Yes, because its saying to do just that. You're telling it to trace all the data that the php file has echoed back. Now, creating a new XML with event.target.data and tracing that, will only give you the xml.
ric_biaAuthor
Inspiring
April 5, 2008
quote:

Originally posted by: dzedward
You're telling it to trace all the data that the php file has echoed back.
Now, creating a new XML with event.target.data and tracing that, will only give you the xml.


But I said that the trace returns ALL the code in the php ( from "<?php" to "?>" ) not only the XML.

Inspiring
April 5, 2008
your code quoted below is loading it as a file on the local drive

you need to load it as http://etc

April 5, 2008
I have never tried using \n formatting xml. It shouldn't be necessary IMO.
ric_biaAuthor
Inspiring
April 5, 2008
But is it normal that:

trace(event.target.data);

prints all the code in the .php file?

I thought it should show only the text echoed in the php.
Inspiring
April 5, 2008
In my limited experience, I have found that creating an XML for testing will help understand how to format it with he PHP. Personally, I have found Flash to be pretty picky with the exact layout for the XML. Once you get it right, it will work. So try creating a test XML and get the import working, then make your PHP format it EXACTLY the same and I bet it will work.

Let us know how it's going.

Sorry, I missed the very first line in your post. So you already know you have the Flash part working. It sounds like you need to tweek your PHP to produce the correctly formatted XML. Make sure it looks EXACTLY like your PHP output XML looks EXACTLY like your test XML and it should work.