0

So I have a situation on my hands. I have an excel file that needs to be made into an XML file, which is a problem for a different posting (XSLT anyone?). That XML file is going to represent a list of about 400 items that are coded into about 15 different categories. Here is a sample of that XML:

<?xml version="1.0" encoding="UTF-8"?>
<hotel>

<hfloor number="18">
<d_location d_code="sw18.10N" d_type="sw" description="Ferbludgit thingamabob">
        <d_image>3e_pic1</d_image>
    <d_image>3e_pic2</d_image>
        <d_image>3e_pic3</d_image>
        <d_image>3e_pic4</d_image>
        <d_image>3e_pic5</d_image>
        <d_video>3e_vid_1</d_video>
        <d_video>3e_vid_2</d_video>
        <d_video></d_video>
</d_location>
</hfloor>

<hfloor number="15">
<d_location d_code="W3" d_type="sw" description="Broken fetzer valve">
        <d_image>3s_pic1</d_image>
</d_location>
    <d_location d_code="LB12" d_type="sw" description="Screwed up whosamadingy">
        <d_image>media/lb15_12/LB-12 LOOKING NORTH.png</d_image>
    <d_image>media/lb15_12/LB-12 LOOKING SOUTH.png</d_image>
        <d_image>media/lb15_12/Pages from Level_15_Link_Beam_12.png</d_image>
    <d_image>media/lb15_12/Pages from Level_15_Link_Beam_12-2.png</d_image>
    <d_image>media/lb15_12/Post Demo from CITC018306365-2.png</d_image>
        <d_image>media/lb15_12/Rebuilt from CITC018306365.png</d_image>
    <d_image>media/lb15_12/WEI LB 12 level 15.png</d_image>
        <d_video>Video 1</d_video>
        <d_video>Video 2</d_video>
        <d_video>Video 3</d_video>
</d_location>
<d_location d_code="LB17" d_type="sw" description="Broken fetzer valve">
        <d_image>3s_pic1</d_image>
</d_location>
</hfloor>

<hfloor number="s">
<d_location d_code="lbs.6e" d_type="sw" description="Whacked flogatron">
        <d_image></d_image>
    <d_image></d_image>
        <d_image></d_image>
        <d_image></d_image>
    <d_image></d_image>
        <d_video></d_video>
        <d_video></d_video>
        <d_video></d_video>
</d_location>
</hfloor>

<hfloor number="s2">
<d_location d_code="W1" d_type="sw" description="Broken fetzer valve">
        <d_image>3s_pic1</d_image>
</d_location>
<d_location d_code="SWS2.3" d_type="sw" description="Whacked flogatron">
        <d_image>media/sw_s2_3/CITC000155966.png</d_image>
    <d_image>media/sw_s2_3/CITC000155983.png</d_image>
        <d_image>media/sw_s2_3/CITC000155996.png</d_image>
        <d_image>media/sw_s2_3/CITC000156003.png</d_image>
        <d_image>media/sw_s2_3/Screen shot 2012-04-19 at 5.54.42 PM.png</d_image>
        <d_image>media/sw_s2_3/WEI SWS2.3.png</d_image>
        <d_video>lbs.6e vid</d_video>
        <d_video></d_video>
        <d_video></d_video>
</d_location>
</hfloor>
</hotel>

The user needs to be able to view all of these in a list - no problem, though that will be a big scroller - but also to FILTER that list by the d_type in the code above. As mentioned, there are 15 of these types, and the user wants 15 radio buttons, one for each, that will re-build the list showing just the selected d_type.

Does anyone have any thoughts as to how to do this? Both the filtering algorithms and how to properly implement it in AS3? I assume I will need to create a second XML object of some sort and translate in the newer, sorted data.

2 Answers 2

2

You should just be able to filter your XML using the XML and XMLList classes.

An excellent overview of that is here: http://joshblog.net/2007/05/08/methods-to-filter-data-with-e4x-in-flash-9/

1
  • Sweet - that's perfect! Thank you so much... that will let me extract the data with pretty serious precision.
    – Mattynabib
    Apr 25, 2012 at 14:54
1

I'd parse the xml in AS3, passing each d_location into function which generates a new object, (representing the item you mentioned) and add that item to both a master list (array), and a type list of arrays. The pseudo code would go something like this

all_items = [];
categories = new Object();
for each floor in hotel {
    for each d_location in floor {
        item = MakeItem(d_location);
        all_items.push(item);
        if (categories[item.type] == null) categories[item.type] = [];
        categories[item.type].push(item);
    }
}

Now you can use you categories for a fast way of accessing all items of that type, as the user presses the appropriate radio button, and all_items if they want to see the lot.

The items objects themselves are not duplicated, just references to them so it's space efficient and fast. Plus having the items as objects makes them easier to work with in AS3 then the XML objects they came from.

You should be able to find plenty of examples for parsing xml in AS3... for example, I use it to parse quest files like so:

for each(var questXMLNode:XMLNode in questXMLNodes) 
{
    quests[quests.length] = new QuestClass(questXMLNode);
}

though yours are two layers deep hotel->hfloor->item

I hope this helps.

1
  • Ah! So I can extract it using the E4X techniques in the first posting, and then create a new array of all of those items using a variation on this technique (if I need to). Great, thank you very much.
    – Mattynabib
    Apr 25, 2012 at 14:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.