Actionscript 3和XML
问题描述:
我想知道如何判断xml的“节点”是否包含某些东西。在下面的前两个<note>
节点包含一个<chord></chord>
节点,但最后一个不怎么能检查它是否包含节点。Actionscript 3和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>
答
但是检查未定义的作品。我想你可以用hasOwnProperty()
方法更好地检查它。有了它,你可以更轻松地过滤你的XML。像这样:
// returns the only the nodes which contain "chord"
trace(xml.note.(hasOwnProperty("chord")));
实现其它方面,本(加上一些额外的XML的东西),可以发现在这里:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/XML.html#hasOwnProperty()
答
我明白了。我必须检查undefined
。
谢谢你似乎是一个更好的办法 – james