Friday, April 2, 2010

Concurrent/Large XML packets causing...

We have a problem when loading XML data which is causing extra data to be returned at the end of some of the expected XML packets - does anybody have any ideas how we can get around this problem?

Our application requests between 3 and 6 data packets which are loaded using URLLoader from seperate class instances which are served by php on our server. This works fine until the XML returned becomes large (around 10000+ chars) at which point one or more of the data packets become corrupted with either spurious characters or data from the other requests appended to the valid XML.

The (edited) code we use to load the XML is this:

?private var linkLoader:URLLoader;
?private var linkRequest:URLRequest;

?override protected function init():void

?{
?// Create link processing objects
?linkLoader = new URLLoader();

?linkLoader.addEventListener(Event.COMPLETE, linksDataLoaded, false, 0, true);
?linkLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, Errors.securityError, false, 0, true);
?linkLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, Errors.httpStatus, false, 0, true);
?linkLoader.addEventListener(IOErrorEvent.IO_ERROR, Errors.IOError, false, 0, true);

?var url:String = Config.interfaceURL + ReaderInterface.LINKS;
?linkRequest = new URLRequest(url);
?linkRequest.contentType = ''text/xml'';
?linkRequest.method = URLRequestMethod.POST;

?}

?// *************************************************************
?private function displayLinks():void
?{
?removeAllLinks();

?// Create request data
?var reqString:String = ReaderInterface.XML_WRAPPER_START + ''%26lt;sessionid%26gt;'' + Config.sid + ''%26lt;/sessionid%26gt;%26lt;issueid%26gt;'' + Config.issueID + ''%26lt;/issueid%26gt;%26lt;page%26gt;'' + magazinePage + ''%26lt;/page%26gt;'' + ReaderInterface.XML_WRAPPER_END;
?var xml:XML = new XML(reqString);
?linkRequest.data = xml;
?linkLoader.data = '''';
?linkLoader.load(linkRequest);
?}
?// *******************************************************************
?private function linksDataLoaded(e:Event):void
?{

?try?{
?var myXML:XML = new XML(linkLoader.data);
?if (myXML.hasOwnProperty(''error''))
?{
?error = true;
?Reader.displayConsole(myXML.error.code + '': '' + myXML.error.message);
?}
?else
?{
?processLinks(myXML);
?}
?}
?catch (e:TypeError)
?{
?Errors.XMLTypeError(e);
?}
?}
?// *******************************************************************

No comments:

Post a Comment