i encount DOMException.HIERARCHY_REQUEST_ERR when navigate the Document object to remove a pecific node, and after google this error code, It says:
"HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not allow children of the type of the newChild node, or if the node to insert is one of this node's ancestors or this node itself, or if this node is of type Document and the DOM application attempts to insert a second DocumentType or Element node"
I have check the node type which i want to remove, both Element and Text type will cause the exception
here is my code
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document dom = builder.parse(new ByteArrayInputStream(smil.getBytes()));
Element root = dom.getDocumentElement();
Node node = root.getFirstChild();
dom.removeChild(node);
it goes
org.w3c.dom.DOMException
at org.apache.harmony开发者_C百科.xml.dom.InnerNodeImpl.removeChild(InnerNodeImpl.java:180)
I found one method can solve this situation
change
dom.removeChild(node);
to
node.getParentNode().removeChild(node);
it seems works for me :-)
精彩评论