Results 1 to 1 of 1
Thread: JAXB Unmarshalling
- 09-01-2010, 02:15 PM #1
Member
- Join Date
- Jun 2010
- Posts
- 3
- Rep Power
- 0
JAXB Unmarshalling
Hi,
I have encountered some troubles unmarshalling XML document via jaxb api. I am building a DOM tree using jaxp and then I need it unmarshalled to Java objects. When i use Unmarshaller's method unmarshal(new File("document.xml")), there is no trouble, everything goes just as I need (of course I need to save created DOM model first). But when I try to unmarshall created document directly, without saving it and passing it to unmarshaller as File, I get this Exception:
It seems to me like some problem with validating, but I dont understand, why it only occurs when I try to use method Unmarshaller.unmarshal(Node node), and not when I save the document first and then pass to Unmarshaller File object of the document.Java Code:Exception in thread "main" javax.xml.bind.UnmarshalException - with linked exception: [org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'projekt'.] at javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException(AbstractUnmarshallerImpl.java:315) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.createUnmarshalException(UnmarshallerImpl.java:503) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:315) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:286) at dota.Main.main(Main.java:125) Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'projekt'. at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195) at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318) at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1887) at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:685) at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl.startElement(ValidatorHandlerImpl.java:549) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.ValidatingUnmarshaller.startElement(ValidatingUnmarshaller.java:78) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startElement(InterningXmlVisitor.java:60) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:137) at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:228) at com.sun.xml.internal.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:111) at com.sun.xml.internal.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:94) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:306) ... 2 more
Of course I get the job done by saving it, but I guess it would be more effective to skip this step. Have anyone an idea where i erred?
Here's the method i use to save the document, maybe there is the crucial point that I am missing:
Thanks for opinions,Java Code:public static void writeXMLFile(String filename, Document document){ try{ Source xmlSource = new DOMSource(document); Result result = new StreamResult(new FileOutputStream(filename)); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); transformer.setOutputProperty("indent", "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "3"); transformer.transform(xmlSource, result); } catch (Exception ex){ System.err.println(ex.getMessage()); } }
Milan Nosal
Similar Threads
-
JAXB Binding
By Fusebox in forum XMLReplies: 0Last Post: 06-11-2010, 10:06 PM -
JAXB: Unmarshalling does not always populate certain classes?
By queuetip in forum XMLReplies: 0Last Post: 02-22-2010, 05:15 AM -
Jaxb
By Paul Richards in forum XMLReplies: 1Last Post: 08-03-2009, 09:56 PM -
JAXB Marshalling
By akbar4ums in forum XMLReplies: 1Last Post: 12-20-2008, 04:39 AM -
JAXB Unmarshalling
By prateek in forum XMLReplies: 0Last Post: 07-10-2008, 06:53 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks