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:

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
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.

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:

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());
        }
    }
Thanks for opinions,
Milan Nosal