This might be tricky using E4X, which, in an attempt to make the overall XML handling a lot easier, apparently also took some useful “garbage” away: there is no getAttributeNode() method (or similar) in E4X, as it is in DOM.

  1. var dataProvider1 : XML = <Text />;
  2. var dataProvider2 : XML = <Text prompt="" />;
  3.  
  4. // Suppose you want to see whether there actually is a "prompt" attribute set on your node,
  5. // and do something clever if it isn’t:
  6. var hasPromptAttribute : Boolean = (dataProvider1.@prompt != null); // guess what: TRUE
  7. var hasPromptAttribute : Boolean = (dataProvider1.@[‘prompt’] != null); // just fancier: TRUE
  8.  
  9. // Maybe a predicate will do?
  10. var hasPromptAttribute : Boolean = (dataProvider1.(attribute (‘prompt’))[0] != null) // TRUE
  11.  
  12. // Count elements in the returning XMLList?
  13. trace (dataProvider1.(attribute (‘prompt’)).length()); // this is "1"; you knew that, right?

The point is, you’re essentially just wasting your time with E4X here. You need to get to the roots, and recall the Object object of ActionScript3. Remember the hasOwnProperty method?

  1. var hasDp1PromptAttribute : Boolean = (dataProvider1.hasOwnProperty(‘prompt’)); // FALSE
  2. var hasDp2PromptAttribute : Boolean = (dataProvider2.hasOwnProperty(‘prompt’)); // TRUE

Phew… :-)