开发者

How to get all validation Errors from SAX-Parser?

i would like to get all validation Errors from the SAX-Parser, but with my snippet i only receive the first. How can i achieve this?

Thank you!

Snippet

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(SAXParseExcep开发者_运维知识库tion saxpe) {
    continueImport = false
    log.error("Error while parsing the import xml", saxpe)
}


Have you tried implementing an ErrorHandler ? This will let you receive and record errors/warnings and fatal errors.

From the doc:

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.

Here is a code example.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜