0

だから私は自分の手に状況があります。XMLファイルにする必要のあるExcelファイルがありますが、これは別の投稿(XSLTの誰か?)にとって問題です。そのXMLファイルは、約15の異なるカテゴリにコード化された約400のアイテムのリストを表します。その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>

ユーザーは、これらすべてをリストで表示できる必要があります(これは大きなスクローラーになりますが、問題ありません)が、上記のコードのd_typeでそのリストをフィルター処理することもできます。前述のように、これらのタイプは15個あり、ユーザーは、選択したd_typeのみを表示するリストを再構築する15個のラジオボタンをそれぞれ1つずつ必要とします。

誰かがこれを行う方法について何か考えがありますか?フィルタリングアルゴリズムとそれをAS3に適切に実装する方法の両方?ある種の2番目のXMLオブジェクトを作成し、新しい、ソートされたデータに変換する必要があると思います。

4

2 に答える 2

2

XMLクラスとXMLListクラスを使用してXMLをフィルタリングできるはずです。

その優れた概要はここにあります:http://joshblog.net/2007/05/08/methods-to-filter-data-with-e4x-in-flash-9/

于 2012-04-24T09:06:51.197 に答える
1

AS3でxmlを解析し、各d_locationを関数に渡して(前述のアイテムを表す)新しいオブジェクトを生成し、そのアイテムをマスターリスト(配列)と配列のタイプリストの両方に追加します。擬似コードは次のようになります

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);
    }
}

これで、ユーザーが適切なラジオボタンを押すと、そのタイプのすべてのアイテムにすばやくアクセスするためのカテゴリと、ロットを表示したい場合はall_itemsを使用できます。

アイテムオブジェクト自体は複製されず、それらを参照するだけなので、スペース効率が高く、高速です。さらに、アイテムをオブジェクトとして使用すると、AS3での操作が簡単になり、元のXMLオブジェクトでの操作が簡単になります。

AS3でxmlを解析するための例をたくさん見つけることができるはずです...たとえば、私は次のようにクエストファイルを解析するためにそれを使用します:

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

あなたは2層の深さのホテル->hfloor->itemですが

これがお役に立てば幸いです。

于 2012-04-24T07:42:35.527 に答える