开发者

java xml validation: getting a better validation error description

I am using javax.xml.validation.Validator from SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI) to perform XSD validation.

I would like to be able to get a better error message back for validation errors. All I currently get is: org.xml.sax.SAXParseException: cvc-minLength-valid: Value '' with length = '0' is not facet-valid with respect to minLength '1' for type 'TypeC开发者_StackOverflow社区ode'.

Is it possible to have the error print out which element or xml fragment is failing validation?

*Edit: I am using the standard java6 xml parsers *Edit2: Sorry for not mentioning - I am using JAXB to read the XML with a contenthandler and a listener (due to the XML being > 1GB most of the time).


Probably not with the validator (maybe one Xerces uses?) you are using. There are other validators, Sun's Multi-Schema Validator for example, but I don't know if any have particularly good error messages for schema validation. For DTD validation Woodstox has better exception messages, but for XML Schema validation it relies on MSV.

However; even the default parser/validator should be able to give you actual error location (or something nearby). If not with error message, you should at least be able to keep track of preceding locations by registering SAX listener, since validator you are using is using SAX API.


Have you tried registering an ErrorHandler with your Validator and accessing the details on the corresponding SAXParseException?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜