XML Node Parents

  1. function numParents(e:XML):int {
  2.     var num:int = 0;
  3.     while (e.parent()!= null) {
  4.         num++;
  5.         e = e.parent();
  6.     }
  7.     return num;
  8. }

Sometimes when reading through XML it's helpful to know how many parents a given node has. This function will do that. I recently used this function in an accordion widget.

This entry was posted in XML and tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *