XML Node Parents

function numParents(e:XML):int {
	var num:int = 0;
	while (e.parent()!= null) {
		num++;
		e = e.parent();
	}
	return num;
}

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.

Leave a Reply

Your email address will not be published. Required fields are marked *