Hi Daniele,
NodeLists [1] are live objects. That is if you make changes to the document these will be immediately reflected in the relevant NodeList objects. This is expected behaviour, though possibly confusing for users.
[1] http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-536297177
"Daniele Madama" <[EMAIL PROTECTED]> wrote on 10/27/2004 11:15:18 AM:
> Hi,
> I don't known if this is the expected behaviour or not, but this result
> strange for me:
>
> I have this code
>
> NodeList childs = this.doc.getDocumentElement().getChildNodes();
> System.out.println("Size = " + childs.getLength());
> for(int i=0; i<childs.getLength(); i++) {
> Node child = childs.item(i);
> System.out.println((i+1)+"/"+childs.getLength()+" - "
> +child.getNodeName());
> }
>
> and the output is
>
> Size = 10
> 1/10 - node1
> 2/10 - node2
> 3/10 - node3
> 4/10 - node4
> 5/10 - node5
> 6/10 - node6
> 7/10 - node7
> 8/10 - node8
> 9/10 - node9
> 10/10 - node10
>
> Well, this is correct, no problem, but if I append any child to other
> element the output is not the same
>
> NodeList childs = this.doc.getDocumentElement().getChildNodes();
> System.out.println("Size = " + childs.getLength());
> Element parent = this.doc.createElement("parent");
> for(int i=0; i<childs.getLength(); i++) {
> Node child = childs.item(i);
> System.out.println((i+1)+"/"+childs.getLength()+" - "
> +child.getNodeName());
> parent.appendChild(child);
> }
>
> the output now is
>
> Size = 10
> 1/10 - node1
> 2/9 - node3
> 3/8 - node5
> 4/7 - node7
> 5/6 - node9
>
> This is for me not the expected result, this is a bug/problem or the
> problem is only mine that don't know the real behaviour of xerces? ;)
>
>
> TIA,
>
>
>
> --
> Daniele Madama
>
> Pro-netics s.r.l.
> Via Elio Lampridio Cerva 127/c
> Roma
> Tel. 0651530849
> http://www.pro-netics.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: [EMAIL PROTECTED]
E-mail: [EMAIL PROTECTED]