Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use SAXParseException effectively in Java
    primarykey
    data
    text
    <p>I'm validating against XMLSchema in Java, and getting SAXParseExceptions thrown when I have non-valid content models.</p> <p>I'm going to be using these exceptions to highlight where the validation has failed - but the SAXParseExceptions seem to be a little too low-level.</p> <p>For example, for a failure on an enumeration, I get the validity error that the value provided doesn't match the content model in one exception, and the element it applies to in the next.</p> <p>I'm thinking I need to have a utility that abstracts a little to merge related errors together and parse exception text into useable exception properties.</p> <p>Is this a reasonable approach, or am I just missing something, or maybe a library or helper class?</p> <hr> <p>Update @timgilbert, thanks for the response.</p> <p>For example, a SAXParseException I found on t'internet</p> <pre><code>cvc-pattern-valid: Value 'en' is not facet-valid with respect to pattern '([a-zA-Z]{1,8})(-[a-zA-Z0-9]{1,8})*' </code></pre> <p>The key things for me are</p> <ul> <li>Element 'en' to which this exception applies. Why can I not call exception.getElement() or something, and why not an XPath to the element in question? More useful with an in-memory document than the line and column number!</li> <li>It's a pattern validation failure. Why can I not get something like a enumeration of possible types of failure and a reference to the appropriate one?</li> <li>The actual pattern that validation has failed against.</li> <li>There'll be another exception thrown next to tell me the value of the 'en' element that caused the problem that I need to merge</li> </ul> <p>An example of what I'd like to be able to do is have people submit a document and have the document highlighted where validation fails with a user friendly message - the error message above kinda doesn't seem very friendly... having to parse by single quotes just feels like an accident waiting to happen :)</p> <p>I think I'm maybe doing it wrong with the 'reference-to-element' thing, and perhaps I should have an identity transform of the document by default as part of the validation, and augment the transformation with validation-error attributes that I can pick out with CSS. That still won't help if I need to parse the messages to make them more friendly though...</p> <p>Re: tight binding, javax.xml.validation.Validator.validate() throws org.xml.sax.SAXException anyway - not sure how I can get away from assuming the binding...</p> <p>Cheers</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload