xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Dupras <bri...@centera.com>
Subject RE: Question about removeChild
Date Fri, 04 Feb 2000 20:59:20 GMT
> Am I missing something in the DOM spec or the Xerces API?

Yes = NodeLists are live.  That means if you created a NodeList of children
of a node, if you delete a child, it gets removed from the NodeList, too.  

Original NodeList
child 0 : <one/>
child 1 : <two/>
child 2 : <three/>

Same NodeList after <parent/>.removeChild(<one/>):

child 0 : <two/>
child 1 : <three/>



One way to work around this is to iteraet backward over the nodelist.  If
you remove the last Node, the other nodes don't change place like if you
delete the first.

Brian


> -----Original Message-----
> From: Kevin Olson [mailto:kevolson@visi.com]
> Sent: Friday, February 04, 2000 1:55 PM
> To: general@xml.apache.org
> Subject: Question about removeChild
> 
> 
> Hello all,
> 
> Using Xerces 1.0.1 and given the following doc...
> 
> <?xml version="1.0"?>
> <root>
>   <one/>
>   <two/>
>   <three/>
> </root>
> 
> I am iterating through a NodeList trying to delete the <one/> 
> element and
> the <two/> element.  I reach the <one/> element and do the following
> (where 'n' is the current node in the NodeList).
>  
> Node parent = n.getParentNode();
> parent.removeChild(n);
> 
> And the <one/> node gets blasted like I would expect.  I 
> would also expect
> to be able to delete the <two/> element in the next iteration of the
> NodeList.  What happens, however, is that the next node in 
> the list is the
> <three/> node.
> 
> It works if I try to delete the <one/> and <three/> node.  
> Just not two
> consecutive nodes with the same parent.  I can show more of 
> the code if
> that would help.
> 
> Am I missing something in the DOM spec or the Xerces API?
> 
> Thanks,
> Kevin
> 
> 
> 

Mime
View raw message