views:

234

answers:

1

I have xml data that I can load into my flex app; however, I need to sort it by node.

I'm trying to create a combobox or listbox that can display a list of locations sorting them either alphabetically or by the category they are in...

I can't get my head around how to format the xml or how to code the flash file to sort according to location name alphabetically and then press a button that will sort it by category 1st and second by name alphabetically.

Should I format the xml like this:

<POIs>
    <location>
            <name>Barbaras Bagels</name>
            <additional nodes inbetween here>
            <category>Restaurants</category>
    </location>
    <location>
            <name>Bobs Powerwashing</name>
            <addition nodes inbetween here>
            <category>Services</category>
    </location>
</POIs>

or Should I format it like this:

<POIs>
    <Restaurants>
        <location>
                <name>Barbaras Bagels</name>
                <additional nodes inbetween here>
        </location>
    </Restaurants>
    <Services>
        <location>
                <name>Bobs Powerwashing</name>
                <addition nodes inbetween here>
        </location>
    </Services>
</POIs>

the above example only has one name in each category but I'm sure you can understand

A: 

You have an array of location objects. So your array would be named "locations" (plural, as you would do with any array).

Get your server to do the dirty work you. If you need only Restaurants have the server return an array with Restaurants. Same thing for Services. If you have a lot of data than this might be a little slow. That's why Flash Player has AMF (aka Flash Remoting) what implementation you need depends on your sever technology.

Anyway, if you do want it interleaved and in XML I guess this is probably the format I would come up with and I would use XPath to select all the relevant nodes from the XML.

<locations>
    <location>
            <name>Barbaras Bagels</name>
            <additional nodes inbetween here>
            <category>Restaurants</category>
    </location>
    <location>
            <name>Bobs Powerwashing</name>
            <addition nodes inbetween here>
            <category>Services</category>
    </location>
</locations>
Luke