[xml] Python, node.name, scope

In the code snippet below (infinite loop prevention and error checking code removed), lines 3 and 4 work properly, and print the node name. Line 6, however, yields the following error:

AttributeError: 'NoneType' object has no attribute 'name'

Is this a scope problem? A bug? What am I doing wrong? It seems to me that line 6 should work if line 3 does.

1: doc = libxml2.recoverDoc(text)
2: node = doc.children
3: name = node.name
4: print "Node:" + name
5: while 1:
6:   name = node.name
7:   if node.name != 'text': break

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]