xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michel Benhamou <bm...@club-internet.fr>
Subject Implementation of previousNode method in TreeWalkerImp
Date Mon, 03 Jan 2000 22:50:16 GMT
When testing the personal.xml file in TreeWalkerView, the previous node
command doesn't give back the right node. It seems there is a mistake in
the implementation of previousNode method in TreeWalkerImp class. If i'm
not missing something, the correct code would be
  public Node               previousNode() {
        Node result;

        if (fCurrentNode == null) return null;

        // get sibling
        result = getPreviousSibling(fCurrentNode);
        if (result == null) {
            result = getParentNode(fCurrentNode);
            if (result != null) {
                fCurrentNode = result;
                return fCurrentNode;
            }
            return null;
        }

        // get the lastChild of result.

        Node lastChild  = getLastChild(result);

//modification
        Node prev = lastChild ;
        while (lastChild != null) {
          prev = lastChild ;
          lastChild = getLastChild(prev) ;
        }

        lastChild = prev ;
// end modification

        // if there is a lastChild which passes filters return it.
        if (lastChild != null) {
            fCurrentNode = lastChild;
            return fCurrentNode;
        }

        // otherwise return the previous sibling.
        if (result != null) {
            fCurrentNode = result;
            return fCurrentNode;
        }

        // otherwise return null.
        return null;
    }

And indeed it gives the good result in TreeWalkerView test.



Mime
View raw message