[XML-SIG] TreeWalker: NextNode

Jag b.jagot@ee.wits.ac.za
Thu, 19 Dec 2002 08:48:25 +0200


Hi...

I have found a bug in the TreeWalker code in PyXML 0.8.1, and previous 
versions.

Using the following snippet of code:
    mywalker = TreeWalker(mydom.documentElement, NodeFilter.SHOW_ALL, None, 1)

    #Now display all the tree values
    print "currentNode: "+mywalker.currentNode.nodeName
    print "entityReference: "+str(mywalker.expandEntityReferences)
    print "WhatToShow: "+str(mywalker.whatToShow)
    print "Filter: "+str(mywalker.filter)

    print "We are gonna attempt a tree printout now"
    
    while 1:
        print mywalker.currentNode.tagName
        next = mywalker.nextNode()
        if next is None: break

We have the following error:

Traceback (most recent call last):
  File "C:\Research\My Work\Impl\wx_tests\tests\xml\XMLExplorer.py", line 
107, in ?
    TreeTest()
  File "C:\Research\My Work\Impl\wx_tests\tests\xml\XMLExplorer.py", line 77, 
in TreeTest
    next = mywalker.nextNode()
  File "C:\PYTHON22\Lib\site-packages\_xmlplus\dom\TreeWalker.py", line 128, 
in nextNode
    next_node = self.__advance()
  File "C:\PYTHON22\Lib\site-packages\_xmlplus\dom\TreeWalker.py", line 141, 
in __advance
    if self.firstChild():
  File "C:\PYTHON22\Lib\site-packages\_xmlplus\dom\TreeWalker.py", line 87, 
in firstChild
    while next_node and not (self.__checkWhatToShow(next_node) \
  File "C:\PYTHON22\Lib\site-packages\_xmlplus\dom\TreeWalker.py", line 160, 
in __checkWhatToShow
    show_bit = 1 << (node._get_nodeType() - 1)
AttributeError: Element instance has no attribute '_get_nodeType'

The NodeIterator does not have this problem. Infact, it seems that it has the 
solution but I cant find what other dependencies are present that prevent the 
modification of code from the NodeIterator to allow the TreeWalker to work.
The NodeIterator just uses node.nodeType but this does not want to work for 
the TreeWalker??

Have others had this problem? I would appreciate some feedback on this issue.

Thanks

Bilal A.R. Jagot
CeTAS
University of the Witwaterrand
Johannesburg
+27 11 717 7226
+27 83 556 3927