ActionScript3和XML

ActionScript3和XML,xml,actionscript-3,Xml,Actionscript 3,我想知道如何判断xml的“节点”是否包含某些内容。在下面的示例中,前两个节点包含一个节点,但最后一个节点不包含该节点,我如何检查它是否包含一个节点 <note><chord></chord> <pitch><step>C</step> <alter>1</alter> <octave&

我想知道如何判断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>

C
1.
5.
1.
1.
一刻钟
2.
2.
G
1.
5.
1.
1.
一刻钟
1.
4.
A.
5.
1.
1.
一刻钟
1.
5.

我明白了。我必须检查
未定义的

但是检查未定义的作品。我认为您最好使用
hasOwnProperty()
方法检查它。使用它,您可以更轻松地过滤XML。像这样:

// returns the only the nodes which contain "chord"
trace(xml.note.(hasOwnProperty("chord")));
可以在这里找到实现此功能的其他方法(加上一些额外的XML内容):


感谢似乎是更好的方式