• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 678
  • Last Modified:

xml from php does not travel to flash cs3

hi
i have 2 php scripts that i have written that taked data from the database and convert it to xml.
both are working: when i test them in the browser i get the xml.
but when i try to load them into flash it does not work. if i use the xml on its own i can get it into flash, but i really want the conversion to work.

the php script 1 is: the first attached code.

and the AS3 code is: the second attached code.


what am i doing wrong?

best regards

ron

<?php
 
$host= "localhost";
$db="";
$username="";
$pass="";
 
$link=mysql_connect($host,$username,$pass) or die(mysql_error());
mysql_select_db($db);
 
$q="SELECT * FROM contacts";
$r=mysql_query($q);
$row=mysql_fetch_assoc($r);
$total_rows=mysql_num_rows($r);
 
//headers
header('Content-type:text/xml');
header('Cache-control:private');
header('Expires:-1');
 
 
?>
<?php  echo('<?xml version="1.0" encoding="utf-8"?>'); ?>
<persons>
  <?php if ($total_rows > 0) { // Show if recordset not empty ?>
  <?php do { ?>
	<person>
		<?php foreach ($row as $column=>$value) { ?>
		<<?php echo $column; ?>>
		<?php echo $row[$column]; ?>
        </<?php echo $column; ?>>
		<?php } ?>
	</person>
    <?php } while ($row = mysql_fetch_assoc($r)); ?>
	<?php } // Show if recordset not empty ?>
</persons>
 
 
AS3:
 
import fl.data.DataProvider;
 
var addRequest:URLRequest = new URLRequest("addBookToXML.php");
var addLoader:URLLoader= new URLLoader(addRequest);
 
var addXML:XML = new XML();
addXML.ignoreWhitespace= true;
 
addLoader.addEventListener(Event.COMPLETE, addLoaded);
 
 
var aArray:Array= new Array();
 
function addLoaded (evt:Event):void {
	addXML= XML(addLoader.data);
	trace(addXML);	
}

Open in new window

0
derrida
Asked:
derrida
  • 14
  • 12
1 Solution
 
Marcus BointonCommented:
Is the XML even getting to Flash? It seems likely that the data is getting through but the XML parser is not liking it. Can you trace the data itself before you try to interpret it, I'm guessing at something like:

function addLoaded (evt:Event):void {
        trace(addLoader.data);  
        addXML= XML(addLoader.data);
        trace(addXML);  
}

AS isn't my thing - is addLoader in scope inside the addLoaded function? It wouldn't be in PHP - you'd need to declare the global.
0
 
derridaAuthor Commented:
hi

thanks for the answer. it was a good idea to trace the data before the xml parser. at least it tells me that it trace the php code and not the xml output.
scope wise there is no problem.

so not the question is hoe can i make the php code to output xml that flash can take? after all i thought that its all good since the php code does output  well formed xml into the browser.

any idea?

best regards

ron
0
 
Marcus BointonCommented:
are you certain the XML is well formed? Can you test it in some other app?
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
derridaAuthor Commented:
hi
if i get the xml in the browser with no error messages, with root tags and the declaration, i think it means it was well formed, no?

i added the output xml i get in IE7 and Firefox and safari. (without the real content obviously).


best regards

ron


 <?xml version="1.0" encoding="utf-8" ?> 
- <persons>
- <person>
  <contactId></contactId> 
  <firstName></firstName> 
  <lastName></lastName> 
  <phoneNum></phoneNum> 
  <email></email> 
  </person>
- <person>
  <contactId></contactId> 
  <firstName></firstName> 
  <lastName></lastName> 
  <phoneNum></phoneNum> 
  <email></email> 
  </person>
- <person>
  <contactId></contactId> 
  <firstName></firstName> 
  <lastName></lastName> 
  <phoneNum></phoneNum> 
  <email>j</email> 
  </person>
</persons>

Open in new window

0
 
Marcus BointonCommented:
Hm. That does look fine. Is it possible you have a text encoding problem in the actual data? What happens if you deliver a static snapshot of that data to your flash app? Also, I'd guess that if the Flash XML parser doesn't like something, it should be generating errors somewhere.
0
 
derridaAuthor Commented:
hi
i have no problem using the static snapshot xml inside flash.

and the error message i get is:
TypeError: Error #1090: XML parser failure: element is malformed.
      at dgtry1_fla::MainTimeline/doGrid()

i cannot see what element is malformed.

best regards

ron
0
 
Marcus BointonCommented:
Well, the way to find out is to cut out bits of the static data until it works, for exmaple cut it down to only 1 person element (perhaps try each of them in turn). There must be something in there. I would strongly suspect a UTF-8 encoding problem as they're quite easy to cause.
0
 
derridaAuthor Commented:
hi
well, the static data is working so i do not see what and why to cut every person:)
i have changes the encoding just to see if it effects anything, but is not.

best regards

ron
0
 
Marcus BointonCommented:
Sorry I misunderstood what you'd tried. You're saying that if you do a request that returns XML from your script directly then it breaks, but if you capture that exact XML and deliver it statically then it works? Do your dynamic and static tests deliver exactly the same content? If so, it's got to be a problem somewhere in the headers as that's pretty much the only place that can be different.
0
 
derridaAuthor Commented:
hi
what i mean is that the php file does output an xml document into the browser. and if i take that xml and save it as a static xml document, i can work with it.

but i cannot work with the xml that the php script output and load it as the php file . and my whole intention is to take data from the database and convert it into xml so i`ll work with it in flash.

i`m actually getting depress with it. on the one hand AS3 is so cool with xml but now this issue is getting me stuck.

best regards

ron
0
 
Marcus BointonCommented:
OK, in that case it's go to be something in the headers. Try doing a "curl -I" (that's a capital i) on your script URL and see what's appearing - it might be something silly like your php.ini sending your xml as text/html, or providing an incorrect encoding header.
0
 
Marcus BointonCommented:
Instead of CURL you could just look at the request/response headers in FireBug.
0
 
derridaAuthor Commented:
hi
can you explain how to do that: request/response headers in FireBug?
i did not get what you mean with the curl-i.

best regards
ron
0
 
Marcus BointonCommented:
Go to a command line (assuming you're on Linux or OS X) and do:

curl -I http://www.example.com/myscript.php

This will make an HTTP request to the given URL, but instead of displaying the body it will display the HTTP headers received.

If you've not discovered FireBug you're in for a treat. Install this in FireFox: http://www.getfirebug.com/
Now hit your XML URL, and then click the firebug icon in the status bar at the bottom. In the panel that appears, click the "Net" tab. you'll see a timeline of HTTP requests with a little triangle next to each. Flip the triangle and you'll see the text of the HTTP request and response headers.
0
 
derridaAuthor Commented:
hi

i`m on windows.

i have downloaded firebug and it looks really useful but when i press the "net" i get nothing.

i hope i can ask you: can you take my php code and test it on any database you have and see if you get the xml like i do?


best regards

ron
0
 
Marcus BointonCommented:
Well the problem isn't getting the XML - that seems to work - it's how the web server describes what it's delivering, which is down to your apache and php.ini settings.

If the browser doesn't handle the content itself, I guess it may not stay in the browser (gets downloaded instead) for firebug to look at. You can get curl for windows here:

http://curl.haxx.se/download.html#Win32
0
 
derridaAuthor Commented:
hi

win does not let me install the curl. tell me that it cannot find "libea32.dll".

ron
0
 
Marcus BointonCommented:
Did you install the SSL libraries linked from that page too? Or try installing the non-ssl version?
0
 
derridaAuthor Commented:
hi
lets leave this, i tried to do it and window froze.

lets return to our subject: do you know what parameter i need to change in my php ini file?


best regards

ron
0
 
Marcus BointonCommented:
Erm, no, because we need to see the HTTP headers to see if anything is actually wrong... Here's an alternative: http://www.rexswain.com/httpview.html Just paste your URL in there and do a GET. You should see all the headers, something like this:

HTTP/1.1·200·OK(CR)(LF)
Date:·Tue,·05·Feb·2008·14:42:15·GMT(CR)(LF)
Server:·Apache/2.0.55·(Ubuntu)·PHP/5.2.4·mod_ssl/2.0.55·OpenSSL/0.9.8a(CR)(LF)
X-Powered-By:·PHP/5.2.4(CR)(LF)
Cache-Control:·max-age=3600(CR)(LF)
Expires:·Tue,·05·Feb·2008·15:42:15·GMT(CR)(LF)
Vary:·Accept-Encoding(CR)(LF)
Content-Length:·7358(CR)(LF)
Connection:·close(CR)(LF)
Content-Type:·text/html;·charset=iso-8859-1(CR)(LF)
(CR)(LF)

Paste what you get in here.
0
 
derridaAuthor Commented:
hi

thanks for the link.

this is the code i get, but it does not look right to me, maybe because it is local.:

   
Rex Swain's HTTP Viewer
http://www.rexswain.com/httpview.html 
Parameters:
URL = http://localhost/addbooktest/addBookToXML.php
UAG = Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser; .NET CLR 2.0.50727)
AEN =
REQ = GET ; VER = 1.1 ; FMT = AUTO
Sending request:
GET /addbooktest/addBookToXML.php HTTP/1.1
Host: localhost
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser; .NET CLR 2.0.50727)
Connection: close

" Finding host IP address...
" Host IP address = 127.0.0.1
" Finding TCP protocol...
" Binding to local socket...
" Connecting to host...
" Sending request...
" Waiting for response...

Receiving Header:
40|(93,D1,1F,D7,AD)·(D9,1D,E2)g(E5)K^(00,F1,E0)(?)%(17,11):s(8A,E1,80,19,C6,9D,97,1A){(1F,9D,D6)&}*a" Elapsed time so far: 0 seconds
" Waiting for additional response until connection closes...

Total bytes received = 43
Elapsed time so far: 0 seconds
HTTP header termination string not found
Content (Length = 43):
       0: 34307C93D11FD7AD 20D91DE267E54B5E 40|""""" ·"""g"K^
      10: 00F1E0283F292517 113A738AE18019C6 """(?)%" ":s"""""
      20: 9D971A7B1F9DD626 7D2A61           """{"""& }*a    

Done
Total elapsed time: 0 seconds

this was what i got.

best regards

ron
0
 
derridaAuthor Commented:
and i see this line: HTTP header termination string not found

but what does it mean?

ron
0
 
Marcus BointonCommented:
Um, trying to access localhost from outside is not going to work!
0
 
Marcus BointonCommented:
You need to put it on a public server somewhere. This is one advantage of firebug and curl - they can work locally.
0
 
Marcus BointonCommented:
Did you fix this yet?
0
 
derridaAuthor Commented:
hi

i did fix the problem. i`m embarrassed to say it but the path was not right. still the interesting thing was that i did not got the right error warning.

in any case i do appreciate your effort.

best regards

ron
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 14
  • 12
Tackle projects and never again get stuck behind a technical roadblock.
Join Now