Finding the Direct Children of a Node : XML Children Node « XML « Python






Finding the Direct Children of a Node


def randomChildElement(self, node): 
    choices = [e for e in node.childNodes 
               if e.nodeType == e.ELEMENT_NODE]    
    chosen = random.choice(choices)                
    return chosen 
           
       








Related examples in the same category

1.Getting Child Nodes
2.toxml Works on Any Nodetoxml Works on Any Node
3.Child Nodes Can Be TextChild Nodes Can Be Text
4.Caching Node Lookups