There are many ways that you can use to check the child existence for XML in AS3. Consider we have a data XML that we need to determine whether “video” node is existed or not:
var myData:XML =
<data>
<item id="0">
<video>example.flv</video>
</item>
<item id="1">
<image>example.jpg</image>
</item>
</data>;
trace("Item with id = 0");
trace(myData.item.(@id == 0).video != undefined);
trace(myData.item.(@id == 0).child("video") != undefined);
trace(myData.item.(@id == 0).child("video").length());
trace("video" in myData.item.(@id == 0));
trace("Item with id = 1");
trace(myData.item.(@id == 1).video != undefined);
trace(myData.item.(@id == 1).child("video") != undefined);
trace(myData.item.(@id == 1).child("video").length());
trace("video" in myData.item.(@id == 1));
// Output:
// Item with id = 0
// true
// true
// 1
// true
// Item with id = 1
// false
// false
// 0
// false
No user commented in " Checking XML Child Existence "
Follow-up comment rss or Leave a TrackbackLeave A Reply