problem with Node.removeChild()

Hi,

as a green beginner, I just encountered a problem concerning the method
removeChild() specified in the class Node. Your kind help and
instruction are highly appreciated.
In order to remove the processing instruction nodes in the DOM generated
by Tidy.parseDOM(), which are often malformatted, the following lines
are written:
... ...
    Node n;
... ...
    NodeList list = n.getChildNodes();
    int i = 0;
    while (i < list.getLength()){
        Node node = list.item(i);
        if (node.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE){
            n.removeChild(node);
            continue;
        }
      i ++;
    }
... ...
There comes sometimes a run-time exception:
"org.w3c.tidy.DOMExceptionImpl: refChild not found.", yet the node to be
removed does exist. How could that happen?

Thanks a lot for your time!

Xianghua Shen

Received on Tuesday, 1 August 2000 23:21:06 UTC