Flex loading (number of results) from xml

error77 used Ask the Experts™
Hi all,
I have a flex project that reads an xml file.
I'm currently using loadXML(); where it will load the whole xml...?
Is there a way where I can specify a search where I could get it to load a specified number of nodes or result?

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

You can't make a URLLoader filter the results returned from a URLRequest. If you have something server-side generating the URL, you could arrange for some parameters to limit what nodes to send.

But, once you have XML loaded from the server into an XML variable, myXML, you can make a new XML assigned to myTempXML containing any subset of the total nodes in a range from, say firstNode:int to lastNode:int, like this:

myTempXML = <temp/>;
for(var i:int = firstNode; i < lastNode && i < myXML.children().length(); i++){

Missed a close-paren there


So, would 'i' be the search? For example, if I add a search inputtext and a button and insert something to search for...how would I do that? Thanks for your time by the way!
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.


In other words. How do I perform a search once XML is loaded. Thanks
You use E4X (EMCAScript for XML) to filter and select XML in ActionScript. It basically lets you use dot-notation to indicate elements by name, and lets you use a small subset of XPath expressions in parentheses. The attached is a sample of how you might do what you're after.
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                width="100%" height="100%">
        import mx.controls.SWFLoader;
        import mx.events.EffectEvent;

        private var pics:XML =
                    <pic> <imageurl>C:\Development\TestFlex\src\testflex\assets\img\camera.png</imageurl> <title>Camera</title> </pic>
                    <pic> <imageurl>C:\Development\TestFlex\src\testflex\assets\img\OkButton.png</imageurl> <title>OK</title> </pic>
                    <pic> <imageurl>C:\Development\TestFlex\src\testflex\assets\img\ErrButton.png</imageurl> <title>ERR</title> </pic>
                    <pic> <imageurl>C:\Development\TestFlex\src\testflex\assets\img\lock18x18.png</imageurl> <title>LOCK</title> </pic>
                    <pic> <imageurl>C:\Development\TestFlex\src\testflex\assets\img\IBM_LOGO_2.png</imageurl> <title>IBM</title> </pic>
                    <pic> <imageurl>C:\Development\TestFlex\src\testflex\assets\img\new-win-icon.png</imageurl> <title>new</title> </pic>
                    <pic> <imageurl>C:\Development\TestFlex\src\testflex\assets\img\Refresh.png</imageurl> <title>Refrexh</title> </pic>
                    <pic> <imageurl>C:\Development\TestFlex\src\testflex\assets\img\warning.png</imageurl> <title>Warn</title> </pic>
                    <pic> <imageurl>C:\Development\TestFlex\src\testflex\assets\img\IBM_LOGO_2.png</imageurl> <title>IBM</title> </pic>
                    <pic> <imageurl>C:\Development\TestFlex\src\testflex\assets\img\IBM_LOGO_2.png</imageurl> <title>IBM</title> </pic>

        private function titleButtonClick():void {
            oddImage.source = pics.pic.(title == imageInputText.text).imageurl;

        private function indexButtonClick():void {
            oddImage.source = pics.pic[parseInt(indexInputText.text)].imageurl;

    <mx:Label text="image title"></mx:Label>
    <mx:TextInput id="imageInputText"/>
    <mx:Button click="titleButtonClick()" label="Get image with title"></mx:Button>

    <mx:Label text="image number"></mx:Label>
    <mx:TextInput id="indexInputText"/>
    <mx:Button click="indexButtonClick()" label="Get image with index"></mx:Button>
    <mx:Image id="oddImage"/>
    <mx:TextArea height="200" width="200" id="referenceTextArea" text="{pics.toXMLString()}"/>

Open in new window


Fantastic! Thank you!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial