Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy doesn't JAXB want to validate
    primarykey
    data
    text
    <ol> <li>I wrote some Java classes and annotated them with the JAXB annotations.</li> <li>After that I used schemagen to generate an xsd.</li> <li>Then I build an object graph and marshalled it to a xml file.</li> <li>I modified the xml file so that it was not valid anymore.</li> </ol> <p>I wanted to use the xsd in the hope the JAXB unmarshalling fails. But it doesn't. Why?</p> <p>JAXB is reading a schema (if the schema XML is wrong JAXB gives an exception) but it seams that JAXB is ignoring the schema while reading.</p> <pre><code> SchemaFactory sf = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = sf.newSchema(getClass().getResource( "/schema1.xsd")); JAXBContext context = JAXBContext.newInstance(Customer.class); Unmarshaller unmarshaller = context.createUnmarshaller(); unmarshaller.setSchema( schema ); Customer c = JAXB.unmarshal(file, Customer.class); </code></pre> <p>The written XML starts like that:</p> <pre><code> &lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt; &lt;ns2:customer xmlns:ns2="http://bla.com/"&gt; </code></pre> <p>Even the attached ValidationEventCollector didn't give any information:</p> <pre><code> unmarshaller.setEventHandler(new JAXBEventCollector()); </code></pre> <p>JAXBEventCollector is:</p> <pre><code> class JAXBEventCollector extends ValidationEventCollector { @Override public boolean handleEvent(ValidationEvent event) { System.out.println(event.getLocator()); return true; } } </code></pre>
    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