开发者

How to get all validation Errors from SAX-Parser?

开发者 https://www.devze.com 2022-12-14 06:01 出处:网络
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?

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

精彩评论

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