Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

problem with JAXB Unmarshalling

843834Jan 5 2010
hi to all

i have a problem during marshal and unmarshal with JAXB 2.0.. i can marshall my xml to get an object instance and using it as unmmarshall input process..but the xml i get it's not valid because the root tag namespace prefix missing (this happen with both validation status(yes or no))..

what i do about unmarshall configuration is to add to package-info class the lines:

@javax.xml.bind.annotation.XmlSchema(
location="./myxml.xsd",
namespace = "http://it.netbureau/provaXml",
elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED,
xmlns = {
@javax.xml.bind.annotation.XmlNs
(
prefix = "tns",
namespaceURI="http://it.netbureau/provaXml"
)
}
)
package it.netbureau.main;


but the xml looks like :

<envelope xmlns:tns="http://it.netbureau/provaXml">
<tns:HEADLINE>...</tns:HEADLINE>
..
</envelope>

instead of <tns:envelope></tns:envelope> so as it gets the validation break down! because envelope haven't got a namespace prefix. this is strange because with qualified elementFormDefault nor unqualified the xml still wrong..

Why should this happen, how i can resolve this?

this is the stack trace error:

javax.xml.bind.UnmarshalException
- with linked exception:
[org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'ENVELOPE'.]
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException(AbstractUnmarshallerImpl.java:315)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.createUnmarshalException(UnmarshallerImpl.java:514)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:215)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:184)
...

thank you

Roby
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 2 2010
Added on Jan 5 2010
0 comments
619 views