Python lxml etree check if node exists
Question: I have this XML:

    
    
    <MasterPage>
        <NextPage>
            <prefix>
    

I want to check if the `prefix` node exists; I tried this, but it didn't work:

    
    
    self.doc=etree.parse(xmlFile)
    if hasattr(self.doc, 'MasterPage/NextPage/prefix'):
    


Answer: 
    >>> from lxml.html import fromstring
    >>> import lxml.html as PARSER
    >>> data = """<MasterPage>
    ...              <NextPage>
    ...                  <prefix>"""
    >>> root = PARSER.fromstring(data) 
    >>> node_list = []
    >>> for ele in root.getiterator():
    ...     node_list.append(ele.tag)
    ... 
    >>> if "prefix" in node_list:
    ...     print "True"
    ... 
    True
    >>> node_list
    ['masterpage', 'nextpage', 'prefix']
    

