java - Error on unmarshaling with generated code (moxy): "A descriptor with default root element ... was not found in the project" -


i generated code using moxy different xsd-files: http://www.forum-datenaustausch.ch/generalinvoiceresponse_400.xsd , http://www.forum-datenaustausch.ch/xmlstandards_generelle_rechnung_beispiele_antwort_4.3_20100901.zip

i generated jaxb-classes both xsd (using moxy). tried unmarshal xml-files (genrated eclipse) code:

public void temptest() throws jaxbexception{     jaxbcontext jc = jaxbcontext.newinstance(<package corresponding type>.responsetype.class);     jc.createunmarshaller().unmarshal(responsetest.class.getresourceasstream("/responses/generalinvoiceresponse_400.xml")); } 

with xml-file of 4.3-type (2nd link) works fine xml of 400-type (1st link) error:

caused by: javax.xml.bind.unmarshalexception  - linked exception: [exception [eclipselink-25008] (eclipse persistence services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.xmlmarshalexception exception description: descriptor default root element {http://www.forum-datenaustausch.ch/de}response not found in project] 

it seems problem name-space. name space different can not see relevant difference in generated code or generated xml - name space consistent. cause problem (where difference) , how solve it?

small addition: tried unmarshal xml marshaled jaxb/moxy-code:

public void marshall() throws jaxbexception, filenotfoundexception {     jaxbcontext jc = jaxbcontext.newinstance(responsetype.class);     objectfactory of = new objectfactory();     jc.createmarshaller().marshal( of.createresponse(of.createresponsetype()),new fileoutputstream("simpleresponse.xml")); } 

this creates simple xml:

<?xml version="1.0" encoding="utf-8"?> <response xmlns="http://www.forum-datenaustausch.ch/de"/> 

unmarshaling yields same error.

when creating jaxbcontext based on model generated xml schema should use the newinstance method takes package name. ensure necessary bits processed.

jaxbcontext jc = jaxbcontext.newinstance("ch.forum_datenaustausch.de"); 

when use jaxbcontext.newinstance(class...) method jaxb implementation assuming started jav classes. since role of objectfactory can played class annotated @xmlregistry objectfactory class generated xml schema automatically picked up. following, still recommend above approach:

jaxbcontext jc = jaxbcontext.newinstance(responsetype.class, objectfactory.class); 

update

thank you! explain why working 1 xsd , not other?

the schema "works" may have global element anonymous type causes @xmlrootelement annotation generated meaning objectfactory not required. other may have global element named complex type causes @xmlelementdecl annotation on objectfactory class generated.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -