PDA

View Full Version : TypeError: Error #1090: XML parser failure: element is malformed.


saife
11-20-2008, 04:43 PM
Hi all.

I'm trying to compile a swf, but a get the following error:

TypeError: Error #1090: XML parser failure: element is malformed.
at xml2_fla::MainTimeline/completeHandler()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunctio n()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/flash.net:URLLoader::onComplete()

The project consists to create a xml file from a php page, that requests data from a data base. Here's the code of php page, quite simple:

<?php
include("../../dirClient/adm/ferramentas/funcoes.php");

conecta();

//header('Content-Type: text/xml');

$string_xml="<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n";

$string_xml .= "<texto>\n";

$sel_texto = resultado("SELECT * FROM tb_home ORDER BY id");

while($row_texto = mysql_fetch_array($sel_texto))
{
$id = $row_texto['id'];
$pt_txt = $row_texto['textoPT'];
$en_txt = $row_texto['textoEN'];

$string_xml .= "\t<txt_home id=\"". $id ."\">\n";
$string_xml .= "\t\t<pt_txt><![CDATA[". $pt_txt . "]]></pt_txt>\n";
$string_xml .= "\t\t<en_txt><![CDATA[". $en_txt . "]]></en_txt>\n";
$string_xml .= "\t</txt_home>\n";

}

$string_xml .= "</texto>";

echo $string_xml;
?>

and here goes the AS 3 code:

import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.xml.XMLDocument;
import flash.events.Event;
import flash.events.ProgressEvent;

var loaderXML:URLLoader = new URLLoader();
loaderXML.addEventListener(Event.COMPLETE, completeHandler);

var urlR:URLRequest = new URLRequest();
urlR.url = "../../workspace/xml_dirClient/xml_home.php";

loaderXML.load(urlR);


function completeHandler(evt:Event):void {
var xml:XML = XML(evt.currentTarget.data);
var xmlDoc:XMLDocument = new XMLDocument();
xmlDoc.ignoreWhite = true;
xmlDoc.parseXML(xml);

var totalFilhos:uint = xmlDoc.firstChild.childNodes.length;

for (var i :uint = 0; i<totalFilhos; i++) {
trace(xmlDoc.firstChild.childNodes[i].attributes.id);
}
}

The fact is, the browser compiles the php file and generate a xml file corectly. Firebug is clear from errors. And most important, if i create a xml file from data generated by php, flash compiles swf correctly.

That's it.

Tnx in advance.

tarafenton
11-20-2008, 05:33 PM
I don't know if this will help. I only read your post quickly and you say it works one way, but I noticed you posted AS3 andxmlDoc.firstChild.childNodes[i].attributes.id is AS2

That could be one of your problems...

saife
11-20-2008, 06:26 PM
I don't know if this will help. I only read your post quickly and you say it works one way, but I noticed you posted AS3 andxmlDoc.firstChild.childNodes[i].attributes.id is AS2

That could be one of your problems...

Thanks tarafeton, but this is not the point. If i try to load a xml file from another structured xml, it works. This problem is happening in this xml file, generated on php. I'm goin' nuts.

tarafenton
11-20-2008, 06:51 PM
make sure the xml created by the php has no spaces on the top.

i know this happened to me too but i work in a team and they handled it after many attempts, i'm looking around to see if I can find anything helpful

Dail
11-20-2008, 09:15 PM
open up the php file in a web browser and look at the XML getting returned. That way you can see were your PHP is writing the XML incorrectly.

Dail
11-20-2008, 09:16 PM
I don't know if this will help. I only read your post quickly and you say it works one way, but I noticed you posted AS3 andxmlDoc.firstChild.childNodes[i].attributes.id is AS2

That could be one of your problems...
He is using XMLDocument, which is the AS3 legacy version of the AS2 XML methods. So, no problem there.

saife
11-20-2008, 10:21 PM
make sure the xml created by the php has no spaces on the top.

i know this happened to me too but i work in a team and they handled it after many attempts, i'm looking around to see if I can find anything helpful

When you say "spaces on the top", do you mean white space before the first line generated by php, the php code itself or xml code tabulation?

saife
11-20-2008, 10:26 PM
open up the php file in a web browser and look at the XML getting returned. That way you can see were your PHP is writing the XML incorrectly.

The xml generated by php seems to be ok. Firefox show me a correctly structured xml. No problem about it.

saife
11-22-2008, 12:49 AM
Hahahhaha. Problem solved, my friends. That's so simple, that i'm feeling like an idiot. Well, here goes the simplest solution ever:

Think with me. At first glance, i was trying to get php data from this address:

urlR.url = "../../workspace/xml_clientDir/xml_home.php";

Note that i was attempting to request the page without processing it, calling it directly and not processed by a server.

So, when debuging in Flash, i've noticed that the data received was the entire code on page.
Well. Let there be light. I changed it to this:

urlR.url = "http://localhost:8888/workspace/xml_clientDir/xml_home.php";

Hahahahah, my friends. That's it. The page is processed by the server and the magic occurs. Flash does not processes pages directly if you don't tell him to request the page from a server. Simple, isn't?

I'm sharing the solution with you all because, when somebody loses two days frying his brain to get the solution to something like this, heheheh. And in this case, i've already faced a problem like this one before, so i'm feeling like a donkey.

Regards!

kurt.vs
12-16-2008, 07:28 PM
Hey Saife,

at first I almost lost it, until I read your post.
Thanks for that one.
In fact, if you think about it, it's logic, but when you
repeatedly see a well parsed doc in FF and not in your
flash, it can drive you mad.

Thanks for sharing.