PDA

View Full Version : Generating XMLListCollection from HTTP Request


showmehow
12-18-2008, 01:06 AM
Hi,

New to this forum and relatively new to flex3 and actionscipt.
Need help finding out why I am having issues with importing an xml file with httpservice into a XMLListCollection.

All I am looking to do is load an xml file into a XMLListCollection with httpservice and then show it in the text area as a list of children within the XMLListCollection.
Tried many methods and cannot get any to work for me??

Code:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" ">
<mx:Script><![CDATA[
import mx.collections.XMLListCollection;
import mx.utils.ObjectProxy;
import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;
import mx.utils.ArrayUtil;

[Bindable]
public var datalist:XMLListCollection;

public function doSend(search:String):void
{
xmlFromDatabase.url = "./includes/flexsearchxml.php?search="+search;
xmlFromDatabase.send();
}

//THIS IS WHERE I CANNOT GET THE HTTPSERVICE REQUEST RESULT STORED IN DATALIST AS AN XMLLISTCOLLECTION< THEN SHOW THE RESULT IN TEST(TEXTAREA)

private function resultHandler(event:ResultEvent):void{

//datalist.source = new XMLList(event.result.data.row);
//datalist = new XMLListCollection(event.result.data.row);
var xmlList:XMLList = new XMLList(event.result.data.row);
datalist.source = xmlList;
//datalist = new XMLListCollection(xmlList);
//datalist = _xlcCatalog;
test.text=datalist.children();
//datalist = event.result.data.row;
//test.text=event.result.toLocaleString();
}

]]>
</mx:Script>

<mx:HTTPService url="./includes/flexsearchxml.php" id="xmlFromDatabase" showBusyCursor="true" result="resultHandler(event)" method="GET" resultFormat="e4x"/>

<mx:TextInput id="textinput" width="478" textAlign="center" keyUp="doSend(textinput.text)"/>

<mx:TextArea id="test" width="300" height="100">
</mx:TextArea>

</mx:Application>



This code comes from a larger application and I have removed surplus un-needed code, when I run this same code using a variable _xlcCatalog, which is an XMLListCollection, everything works fine, and the resulting XMLList from _xlcCatalog is listed in the text area on keyup within the textinput field.

Any assistance is appreciated, thanks
Showmehow

wvxvw
12-18-2008, 05:27 AM
Then what result do you get?
What is your XML looking like?
What do you see when you trace(event.result.data.row) or
trace(event.result.data.row.toXMLString())?
You don't need to create new XMLList because event.result.data.row is XMLList.
Maybe you need to call toXMLString() on it, because otherwise you'll see only the text nodes (if your XMLList is 1 level deep, then you wan't see anything).

showmehow
12-18-2008, 10:27 PM
Hi wvxvw,
Thanks for your post,
I ended up getting this sorted using the following code:
private function resultHandler(event:ResultEvent):void{
var x:XML = event.result as XML;
var xl:XMLList = XMLList(x.children());
var datalist:XMLListCollection = new XMLListCollection(xl);
test.text=datalist.children();
}

and reworking my xml file a little so that the information required sat within [row] nodes within a root [data] node, eg:

<?xml version="1.0" encoding="iso-8859-1"?>
<data>
<row>
<info1>1</info1>
<info2>2</info2>
</row>
<row>
<info1>1</info1>
<info2>2</info2>
</row>
</data>

Hope this may help anyone else with similar issues
Regards
Showmehow