我想从 SAX-Parser 获取所有验证错误,但对于我的代码片段,我只收到第一个。我怎样才能实现这个目标?
谢谢!
片段
def factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
def xml = new StreamSource(inputStream)
def xsd = new StreamSource(new FileReader(schema), systemId)
try {
factory?.newSchema(xsd)?.newValidator()?.validate(xml)
} catch(SAXParseException saxpe) {
continueImport = false
log.error("Error while parsing the import xml", saxpe)
}
最佳答案
您是否尝试过实现 ErrorHandler ?这将使您接收并记录错误/警告和 fatal error 。
来自文档:
If a SAX application needs to implement customized error handling, it must implement this interface and then register an instance with the XML reader using the setErrorHandler method. The parser will then report all errors and warnings through this interface.
这是一个code example .
关于java - 如何从 SAX-Parser 获取所有验证错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1887680/