我是这样解决的: DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setValidating(true);
dbf.setIgnoringComments(true);
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource(new java.io.ByteArrayInputStream(xmlStr.getBytes()));
Document doc = db.parse(is);
DocumentImpl docImpl = (DocumentImpl) doc;