Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » [Moxy] Problem on unmarshalling using Document instead of InputStream
[Moxy] Problem on unmarshalling using Document instead of InputStream [message #1043192] Wed, 17 April 2013 11:57 Go to next message
moritz du is currently offline moritz du
Messages: 98
Registered: February 2010
Member
I have code that unmarshalls xml using
Unmarshaller.unmarshall(Source(InputStream), Class<T>)


Now i hav to refactor the code to use

Unmarshaller.unmarshall(Document, Class<T>)


but this doesn't work:
Exception Description: An error occurred unmarshalling the document
Internal Exception: org.xml.sax.SAXParseExceptionpublicId: ; systemId: ; lineNumber: 0; columnNumber: 0; cvc-elt.1: Cannot find the declaration of element 'invoice:request'.


The xsd i use is from here and i use this examples

Here is the complete test code:
    @Test
    public void test() throws Exception {
        Unmarshaller um;
        JAXBContext jaxbContext = JAXBContext
                .newInstance("....generatedClasses.invoice.general430.request");
        um = jaxbContext.createUnmarshaller();

        InputStream xmlIs = SingleTests.class.getResourceAsStream("/430_requests/dentist_ersred_TG_430.xml");

        SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema = sf.newSchema(this.getClass().getResource("/xsd/" + "generalInvoiceRequest_430.xsd"));
        //
        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
        Document doc;
        try {
            DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
            doc = docBuilder.parse(xmlIs);
        } catch (Exception e) {
            throw new Exception("Problem on recognizing invoice type of given xml, cause: ", e);
        }
        //
        um.setSchema(schema);
        um.unmarshal(doc, ....generatedClasses.invoice.general430.request.RequestType.class);

    }


this code is failing as stated above but if the InputStream is directly fed to unmarshall (the Document building block must be commented out) it works fine
Re: [Moxy] Problem on unmarshalling using Document instead of InputStream [message #1043329 is a reply to message #1043192] Wed, 17 April 2013 15:08 Go to previous messageGo to next message
Denise Smith is currently offline Denise Smith
Messages: 11
Registered: July 2009
Junior Member
Hi

Try adding the following:

    docBuilderFactory.setNamespaceAware(true);

Hope that helps!
Denise
Re: [Moxy] Problem on unmarshalling using Document instead of InputStream [message #1043333 is a reply to message #1043329] Wed, 17 April 2013 15:13 Go to previous message
moritz du is currently offline moritz du
Messages: 98
Registered: February 2010
Member
Thank You! It is working now Smile
Previous Topic:Static Metamodel gencode error ... for wildcard Collection field
Next Topic:One to many and Many to One MOXy @XmlInverseReference EclipseLink 2.5
Goto Forum:
  


Current Time: Wed Oct 01 16:17:50 GMT 2014

Powered by FUDForum. Page generated in 0.13117 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software