I'm trying to create an expression from an XML. Reading from top node I want to put the node one by one into a stack, once I hit a closing tag I want to pop all elements in the stack. How do I check the end of a tag ?.
TIA,
John
Answer:
OK, I think I've the solution, using a recursive function like this:
def findTextNodes(nodeList):
for subnode in nodeList:
if subnode.nodeType == subnode.ELEMENT_NODE:
print("element node: ",subnode.tagName)
# call function again to get children
findTextNodes(subnode.childNodes)
print('subnode return: ', subnode.tagName)
elif subnode.nodeType == subnode.TEXT_NODE:
print("text node: ",subnode.data)
When the 'subnode return' it hits the closing tag!.
Thanks everybody!.