Hi Utsav,
Lists in DOM are required by the standard to be "live".
So if you have a parent node whose children are (a,b,c), then
NodeList l = parent.getChildNodes;
// l = (a,b,c)
Node child1 = l.item(1);
l.removeChild(child1);
then suddenly l = (b,c)
So iterating over the list using an int as an index into the list is a
really bad idea :-). Because childList is changing, your code below is
actually copying and deleting every 2nd child of the parent.
try
while (!childList.empty())
{
// get childList[0]
// copy & delete from parent
}
Regards,
Simon
On Mon, 2003-07-21 at 04:35, [EMAIL PROTECTED] wrote:
> Hi,
> when I am trying to move all the child nodes from one Node to another
> Element, it moves only the text nodes and skips all other nodes. I have
> attached below the relevant part of my code, please point out the
> mistake I am doing.
>
>
> NodeList childlist = node.getChildNodes();
> for(int i=0;i<childlist.getLength();i++)
> nodeEL.appendChild(node.removeChild(childlist.item(i)));
> nodeEL.normalize();
> node.getParentNode().replaceChild(nodeEL, node);
>
> here node is a Node and nodeEL is defined to be an Element.
> will this method copy the attributes of child nodes as well ??
>
> Thanks,
> Utsav
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]