2011-12-03 8 views
0

xmlの「ノード」に何かが含まれているかどうかを知る方法は不思議でした。下の最初の2つの<note>ノードには<chord></chord>ノードが含まれていますが、最後のノードにはノードが含まれているかどうかを確認する方法がありません。Actionscript 3 and XML

<note><chord></chord> 
       <pitch><step>C</step> 
        <alter>1</alter> 
        <octave>5</octave> 
       </pitch> 
       <duration>1</duration> 
       <voice>1</voice> 
       <type>quarter</type> 
       <notations><dynamics><f></f> 
        </dynamics> 
        <technical><string>2</string> 
         <fret>2</fret> 
        </technical> 
       </notations> 
      </note> 
      <note><chord></chord> 
       <pitch><step>G</step> 
        <alter>1</alter> 
        <octave>5</octave> 
       </pitch> 
       <duration>1</duration> 
       <voice>1</voice> 
       <type>quarter</type> 
       <notations><dynamics><f></f> 
        </dynamics> 
        <technical><string>1</string> 
         <fret>4</fret> 
        </technical> 
       </notations> 
      </note> 
      <note><pitch><step>A</step> 
        <octave>5</octave> 
       </pitch> 
       <duration>1</duration> 
       <voice>1</voice> 
       <type>quarter</type> 
       <notations><dynamics><f></f> 
        </dynamics> 
        <technical><string>1</string> 
         <fret>5</fret> 
        </technical> 
       </notations> 
      </note> 

答えて

1

未定義の作品をチェックします。私はあなたがhasOwnProperty()方法でそれをよく点検できると思う。 XMLを使用すると、XMLをより簡単にフィルタリングできます。この(プラスいくつかの追加のXMLのもの)を実装するための

// returns the only the nodes which contain "chord" 
trace(xml.note.(hasOwnProperty("chord"))); 

他の方法こっち見つけることができます::そう同様

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/XML.html#hasOwnProperty()

+0

おかげで、より良い方法のように思えます – james

0

私はそれを得ました。私はundefinedを確認しなければならなかった。