2012-04-27 9 views
0

E4Xを使用して自分のXML文書を掘り下げたいという結果を得ることができません。私は、以下のXMLを使用して、やりたいexampleWhatについて、d_type SWを持ってd_locationsのすべてを見つけ、その後、コードとhfloor番号が含まれ、すべてのSWのd_typesのリストを作成している - これはd_typeより上のレベルです。 E4Xを使用して、親属性の子属性のリストを作成するにはどうすればよいですか?

だから一例を説明するために、私は出力には、このようなリストが欲しい:

TYPE:SW

階18:SW18.10N

階15:SW15。 W2

フロア15:LB12

階15:LB17

フロアS2:SWS2.3

私はE4Xを使用していることをどのように行うことができますか?本当にありがとう!

Mattynabibは

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

<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="W1" d_type="PSW" description="Broken fetzer valve"> 
     <d_image>3s_pic1</d_image> 
</d_location> 
<d_location d_code="SW15.W2" d_type="SW" description="Broken fetzer valve"> 
     <d_image>3s_pic1</d_image> 
</d_location> 
<d_location d_code="W3" d_type="LB" 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> 
<d_location d_code="LB8" d_type="EB" description="Broken fetzer valve"> 
     <d_image>3s_pic1</d_image> 
</d_location> 
<d_location d_code="W14" d_type="CB" description="Broken fetzer valve"> 
     <d_image>3s_pic1</d_image> 
</d_location> 
</hfloor> 


<hfloor number="S2"> 
<d_location d_code="W3" d_type="LB" 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> 
<d_location d_code="LB17" d_type="ES" description="Broken fetzer valve"> 
     <d_image>3s_pic1</d_image> 
</d_location> 
<d_location d_code="LB8" d_type="SW" description="Broken fetzer valve"> 
     <d_image>3s_pic1</d_image> 
</d_location> 
</hfloor> 

</bldg> 

答えて

0

次の2つのプロセスでそれを行う必要があります。最初にd_locationノードを収集します。これはXMLListを返します。次に、それの各要素について、あなたが望むフロアコードを含むh_floorノードである親を見つけます。

var xml:XML = <bldg><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="W1" d_type="PSW" description="Broken fetzer valve"> 
     <d_image>3s_pic1</d_image> 
    </d_location> 
    <d_location d_code="SW15.W2" d_type="SW" description="Broken fetzer valve"> 
     <d_image>3s_pic1</d_image> 
    </d_location> 
    <d_location d_code="W3" d_type="LB" 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> 

    <d_location d_code="LB8" d_type="EB" description="Broken fetzer valve"> 
      <d_image>3s_pic1</d_image> 
    </d_location> 
    <d_location d_code="W14" d_type="CB" description="Broken fetzer valve"> 
      <d_image>3s_pic1</d_image> 
    </d_location> 
</hfloor> 


<hfloor number="S2"> 
    <d_location d_code="W3" d_type="LB" 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> 
    <d_location d_code="LB17" d_type="ES" description="Broken fetzer valve"> 
     <d_image>3s_pic1</d_image> 
    </d_location> 
    <d_location d_code="LB8" d_type="SW" description="Broken fetzer valve"> 
     <d_image>3s_pic1</d_image> 
    </d_location> 
</hfloor> 

;

その後、あなたは2段階のプロセスを行います。この関数を作成:

function find(type:String) { 
    var D_LOCATIONS:XMLList = (xml..d_location.(@d_type==type)); 
    for each (var loc:XML in D_LOCATIONS) { 
     trace("Floor:", loc.parent()[email protected], [email protected]_code);   
    } 
} 

find("SW"); 
+0

ようにそれを呼び出すには、ありがとう - 非常に便利! – Mattynabib

関連する問題