有个问题向大家请教一下
目前应用中要不断的接收客户端上发的XML格式数据,
在服务端使用了DOM4J进行DTD校验
实现的过程中,每次验证XML数据都要使用SAXReader重新加载一下DTD文档(同一个DTD文档),
这样要进行大量的IO,对系统的性能会有影响,能否让所有的请求使用一个DTD文档校验,即只加载一次
如果所有的请求全用一个SAXReader,在并发时,是否会产生错误?
每次获得SAXReader的代码如下: /**
* 指定SAX解析的的DTD校验文件
* @param dtdPath DTD校验文件路径
* @param dtdFile 用于校验的文件
* @return
*/
private static SAXReader getSaxReader(final String dtdPath, final String dtdFile) { final String filePath = dtdPath + System.getProperty("file.separator") + dtdFile;
SAXReader saxReader = new SAXReader();
saxReader.setEntityResolver(new EntityResolver() {
public InputSource resolveEntity(String publicId, String systemId) throws SAXException,
IOException {
// 指定DTD校验
InputSource inputSource = new InputSource(filePath);
inputSource.setEncoding(Globals.ENCODING);
return inputSource;
}
});
return saxReader;
}
此外,对于大多数情况,XML解析中DTD验证是否开启?
目前应用中要不断的接收客户端上发的XML格式数据,
在服务端使用了DOM4J进行DTD校验
实现的过程中,每次验证XML数据都要使用SAXReader重新加载一下DTD文档(同一个DTD文档),
这样要进行大量的IO,对系统的性能会有影响,能否让所有的请求使用一个DTD文档校验,即只加载一次
如果所有的请求全用一个SAXReader,在并发时,是否会产生错误?
每次获得SAXReader的代码如下: /**
* 指定SAX解析的的DTD校验文件
* @param dtdPath DTD校验文件路径
* @param dtdFile 用于校验的文件
* @return
*/
private static SAXReader getSaxReader(final String dtdPath, final String dtdFile) { final String filePath = dtdPath + System.getProperty("file.separator") + dtdFile;
SAXReader saxReader = new SAXReader();
saxReader.setEntityResolver(new EntityResolver() {
public InputSource resolveEntity(String publicId, String systemId) throws SAXException,
IOException {
// 指定DTD校验
InputSource inputSource = new InputSource(filePath);
inputSource.setEncoding(Globals.ENCODING);
return inputSource;
}
});
return saxReader;
}
此外,对于大多数情况,XML解析中DTD验证是否开启?
public InputSource resolveEntity(String publicId, String systemId) throws SAXException,
IOException {
// 指定DTD校验
InputSource inputSource = new InputSource(filePath);
inputSource.setEncoding(Globals.ENCODING);
return inputSource;
}
}
可以多个对象同用一个 byte[]
没有覆盖saxbuilder,只是重用了EntityResolver里面的filestream