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!

namespace prefix problem marshalling with jaxb

843834Jan 14 2009 — edited Jan 18 2010
HI,

I am using JAXB to unmarshal and marshal XML defined by a XML schema (elementFormDefault qualified).
The unmarshalling is fine and works as expected, but the generated XML when marshalling back is not valid and produces error messages when I try to unmarshal it again.

I think the problem is with the namespaces. The produced XML does not have a default namespace only the schema namespace associated to a prefix. All elements are prefixed with this prefix except the root element, which results in failing the validation.

I can not persuade JAXB to use the schema NS as default namespace as I want to. I tried using a custom NamespacePrefixMapper, which returns "" for the schema NS. Unfortunately this is ignored, even though the generated XML does still not have a default NS declaration (xmlns="... is missing altogether).
I noticed that my custom prefix mapper is used, but in addition to the schema NS also a empty NS ("") is processed. I tried to set a prefix to that empty NS, but it did not work. I am guessing since the empty NS is processed after the schema NS and also requests to be the default, that this somehow prevents the schema NS to be the default.

If I specify a non empty prefix value (like "nsx") for the schema NS, it is going to be used for all elements except the root and I am back the initial problem. Besides, I would really like the generated XML to be without unnecessary prefixes.

I don't know what I am missing.

Any help very much appreciated!

Many thanks,
Flo
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 15 2010
Added on Jan 14 2009
1 comment
2,124 views