DocumentBuilderFactory domfac = DocumentBuilderFactory.newInstance();
InputStream is = null;
try {
DocumentBuilder domBuilder = domfac.newDocumentBuilder();
domBuilder.setEntityResolver(new EntityResolver() {
public InputSource resolveEntity(String publicId,
String systemId) throws SAXException, IOException {
LogUtil.INFO_LOGGER.info("systemId = " + systemId);
// if
// (systemId.equals("file:///D:/ProfessionalSoftware/Workspace/ERICSSONFLOWTODB/MeasDataCollection.dtd"))
// {
if (systemId
.equals("file:///home/ffcs/ERICSSONFLOW/ERICSSONFLOWTODB/MeasDataCollection.dtd")) {
// 一种方式,即忽略DTD,新建一个默认的空XML来代替
return new InputSource(new ByteArrayInputStream(
"<?xml version='1.0' encoding='GBK'?>"
.getBytes()));
}
return null;
}
});
is = new FileInputStream(new File(xmlStr));
Document doc = null;
try {
doc = domBuilder.parse(is);
} catch (Exception e) {
LogUtil.ERROR_LOGGER.error("找不到文件=", e);
LogUtil.INFO_LOGGER.info("解析异常:" + e.getMessage());
}
Element root = doc.getDocumentElement();
NodeList node = root.getChildNodes();
InputStream is = null;
try {
DocumentBuilder domBuilder = domfac.newDocumentBuilder();
domBuilder.setEntityResolver(new EntityResolver() {
public InputSource resolveEntity(String publicId,
String systemId) throws SAXException, IOException {
LogUtil.INFO_LOGGER.info("systemId = " + systemId);
// if
// (systemId.equals("file:///D:/ProfessionalSoftware/Workspace/ERICSSONFLOWTODB/MeasDataCollection.dtd"))
// {
if (systemId
.equals("file:///home/ffcs/ERICSSONFLOW/ERICSSONFLOWTODB/MeasDataCollection.dtd")) {
// 一种方式,即忽略DTD,新建一个默认的空XML来代替
return new InputSource(new ByteArrayInputStream(
"<?xml version='1.0' encoding='GBK'?>"
.getBytes()));
}
return null;
}
});
is = new FileInputStream(new File(xmlStr));
Document doc = null;
try {
doc = domBuilder.parse(is);
} catch (Exception e) {
LogUtil.ERROR_LOGGER.error("找不到文件=", e);
LogUtil.INFO_LOGGER.info("解析异常:" + e.getMessage());
}
Element root = doc.getDocumentElement();
NodeList node = root.getChildNodes();