Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This how we did it. I had to find a way to validate the xml file versus an xsd corresponding to the version of the xml since we have many apps using different versions of the xml content.</p> <p>I didn't really find any good examples on the net and finally finished with this. Hope this will help.</p> <pre><code>ValidationEventCollector vec = new ValidationEventCollector(); SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); URL xsdURL = getClass().getResource("/xsd/" + xsd); Schema schema = sf.newSchema(xsdURL); //You should change your jaxbContext here for your stuff.... Unmarshaller um = (getJAXBContext(NotificationReponseEnum.NOTIFICATION, notificationWrapper.getEnteteNotification().getTypeNotification())) .createUnmarshaller(); um.setSchema(schema); try { StringReader reader = new StringReader(xml); um.setEventHandler(vec); um.unmarshal(reader); } catch (javax.xml.bind.UnmarshalException ex) { if (vec != null &amp;&amp; vec.hasEvents()) { erreurs = new ArrayList &lt; MessageErreur &gt; (); for (ValidationEvent ve: vec.getEvents()) { MessageErreur erreur = new MessageErreur(); String msg = ve.getMessage(); ValidationEventLocator vel = ve.getLocator(); int numLigne = vel.getLineNumber(); int numColonne = vel.getColumnNumber(); erreur.setMessage(msg); msgErreur.setCode(ve.getSeverity()) erreur.setException(ve.getLinkedException()); erreur.setPosition(numLigne, numColonne); erreurs.add(erreur); logger.debug("Erreur de validation xml" + "erreur : " + numLigne + "." + numColonne + ": " + msg); } } } </code></pre>
 

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