我是这样解决的: 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;

解决方案 »

  1.   

    顺便再问大家一个问题:
    怎么给一个DOM设置DTD验证属性呀,也就是说,有没有方法或者属性设置给一个DOM加上这么一句话:<!DOCTYPE OMSInfo SYSTEM "d:/test.dtd">
      

  2.   

    另外,将一个DOM转成字符串的时候,会包含<?xml version="1.0" encoding="UTF-8"?>这么一句话,有没有什么属性设置,可以在转换的时候,不包含这句话的!!在线等