Reputation: 2663
I was wondering how to tell if a "node" of xml contained something. In the below the first two <note>
nodes contain a <chord></chord>
node but the last one does not how could I check if it contains a node.
<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>
Upvotes: 0
Views: 114
Reputation: 2065
However checking for undefined works. I think you can better check it with the hasOwnProperty()
method. With it you can filter your XML a bit more easy. Like so:
// returns the only the nodes which contain "chord"
trace(xml.note.(hasOwnProperty("chord")));
Other ways to implement this (plus some additional XML stuff) can be found over here:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/XML.html#hasOwnProperty()
Upvotes: 1