You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xerces.apache.org by "Timm, Sean" <ST...@mailgo.com> on 2000/02/10 01:43:13 UTC

My problem or problem with getLength?

I've got a method that gets passed in a document object.  When I call it the
first time, the getLength call returns 4.  I remove a node based on some
criteria.  Later on, this function gets called again and the same document
is passed in.  This second time, the getLength call *also* returns 4
(instead of 3 like I would expect).  However, node.item[3] is now null.  I
haven't traced it through the Xerces calls, but it looks like removeChild is
supposed to call changed() which flags it to update on the getLength()
call...is there something I'm missing?
---------------------------------------------------------------
The sample code is as follows:

    NodeList nodelist = document.getChildNodes();
    i = nodelist.getLength();
    
    // Loop through all root child nodes of the document.
    for (int j = 0; j < i; j++) {
        Node node = nodelist.item(j);
        
        if(j == 1) {
            node.getParentNode().removeChild(node);
            i--;
            j--;
        }
    }
---------------------------------------------------------------
- Sean T.

Re: My problem or problem with getLength?

Posted by Andy Clark <an...@apache.org>.
"Timm, Sean" wrote:
> I've got a method that gets passed in a document object.  When I 
> call it the first time, the getLength call returns 4.  I remove 
> a node based on some criteria.  Later on, this function gets 
> called again and the same document is passed in.  This second 
> time, the getLength call *also* returns 4 (instead of 3 like I 
> would expect).  However, node.item[3] is now null.  I haven't 
> traced it through the Xerces calls, but it looks like removeChild 
> is supposed to call changed() which flags it to update on the 
> getLength() call...is there something I'm missing?

The method removeChild() throws an exception in NodeImpl. And
ElementImpl gets its behavior for removeChild from NodeContainer.

The current code in CVS does call changed(). Check the code in
NodeContainer#internalRemoveChild(Node,int):Node. The only way
that it wouldn't call this method is if an exception occurred.

-- 
Andy Clark * IBM, JTC - Silicon Valley * andyc@apache.org