Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is the <em>fourth</em> hour that I'm trying to find the source of the problem. After much struggle, now, I'm confident that you're missing a <em>single line of code</em> to be able to rise to glorious heights!</p> <p>The problem is that <code>DocumentBuilderFactory</code> created via <code>DocumentBuilderFactory.newInstance()</code> by default <em>isn't namespace aware</em>—yeah.</p> <p>You can overcome this in two ways:</p> <ol> <li><p>make your <code>DocumentBuilderFactory</code> namespace aware:</p> <p><a href="http://docs.oracle.com/javase/7/docs/api/javax/xml/parsers/DocumentBuilderFactory.html#setNamespaceAware%28boolean%29"><code>DocumentBuilderFactory.setNamespaceAware(true);</code></a></p></li> <li><p>or use a <code>StreamSource</code> while unmarshalling and drop the <code>DocumentBuilder</code> and his little friends altogether:</p> <p><a href="http://docs.oracle.com/javase/7/docs/api/javax/xml/bind/Unmarshaller.html#unmarshal%28javax.xml.transform.Source,%20java.lang.Class%29"><code>Unmarshaller.unmarshal(StreamSource, Class&lt;T&gt;);</code></a></p></li> </ol> <p>In case of the second choice you're to do it like this.</p> <pre><code>InputStream xsdStream = ... InputStream xmlStream = ... SchemaFactory f = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema s = schemaFactory.newSchema(xsdStream); JAXBContext c = JAXBContext.newInstance(CalculateBorrowingDataResponseType.class); Unmarshaller u = c.createUnmarshaller(); u.setSchema(schema); CalculateBorrowingDataResponseType b = u.unmarshal(new StreamSource(xmlStream), CalculateBorrowingDataResponseType.class); </code></pre> <p>By the way, on this <em>schema-awareness-ness-document-builderness-awesomeness</em> there is a <em>lot</em> info in the top section of the <a href="http://docs.oracle.com/javase/7/docs/api/javax/xml/bind/Unmarshaller.html"><code>Unmarshaller</code> class' documentation</a>, you should definitely check that out!</p>
 

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