Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Really strange when i changed my code to this </p> <pre><code>public class UnMarshallXML { /** * @param args * @throws SAXException */ public static void main(String[] args) throws SAXException { Destination destination=new Destination(); try { destination=(Destination)unmarshal(Destination.class,new FileInputStream(new File("C:/Users/Raisonne/Desktop/jaxb/jaxb-ri-20101119/bin/destination.xml"))); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (JAXBException e) { e.printStackTrace(); } System.out.println(destination.getName()); } public static &lt;T&gt; T unmarshal( Class&lt;T&gt; docClass, InputStream inputStream ) throws JAXBException, SAXException { String packageName = docClass.getPackage().getName(); System.out.println(packageName); JAXBContext jc = JAXBContext.newInstance( packageName ); Unmarshaller u = jc.createUnmarshaller(); SchemaFactory schemaFactory=SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema=schemaFactory.newSchema(new File("C:/Users/Raisonne/Desktop/jaxb/jaxb-ri-20101119/bin/destination.xsd")); u.setSchema(schema); u.setEventHandler( new ValidationEventHandler() { // allow unmarshalling to continue even if there are errors public boolean handleEvent(ValidationEvent ve) { // ignore warnings if (ve.getSeverity() != ValidationEvent.WARNING) { ValidationEventLocator vel = ve.getLocator(); System.out.println( "Line:Col[" + vel.getLineNumber() + ":" + vel.getColumnNumber() + "]:" + ve.getMessage()); } return true; } }); // XMLValidator xmlValidator=new XMLValidator(); //xmlValidator.validateXMLToSchema(u, null,inputStream); @SuppressWarnings("unchecked") JAXBElement&lt;T&gt; doc = (JAXBElement&lt;T&gt;)u.unmarshal( inputStream ); return doc.getValue(); </code></pre> <p>}</p> <p>}</p> <p>everything started working like charm..</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