How does jaxb determine the list of namespace prefix declarations whem marshalling an object? I used xjc to compile java classes for ebics (ebics schema). When I create an instance for an ebicsRequest it looks like this:

I have used a custom NamespacePrefixMapper to declare the default namespace and prefixes for ds and xsi. For the namespace ds it works fine. But for the default namespace it does not. It is declared two times once as ns2 and once as "" the latter coming from my custom NamespacePrefixMapper.getPreDeclaredNamespaceUris. I have played around a lot with this class. Also I tried to use the package-info.java but I was not able to make jaxb use "http://www.ebics.org/H003" as default namespace. What I also do not understand is the appearance of ns4 and ns5 which are not at all part of the xml document.

Hi skaffman, the problem about using XMLStreamWriter as suggested in the answer for the above question is: I want to marshal into an org.w3c.dom.Document. I was not able to add a proper signature to the jaxb instance of my document by marhalling a fragment of the document and the sign it. The marshalled fragment looks different from the fragment of the overall marshalled document (again because of namespace declarations) so the signature was not valid when marshalling the whole document. So I went for marshalling into a Dom Document and then add the signature and then serialize. :-(
–
WilberforceFeb 2 '11 at 11:15

How do you traverse the document a 2nd time? Using string manipulation?
–
MRalwasserApr 2 '14 at 10:36

No, it is done before the document is serialized by iterating over all child nodes for every element in the DOM tree starting at the root node.
–
RebootApr 2 '14 at 14:08

I added a SOAPHandler<SOAPMessageContext> to my service and called this utility in the handleMessage(SOAPMessageContext context) method and it worked like a charm. Now my CXF webservice strips the unused namespaces and the .NET service it connect to doesn't complain because the root element of the SOAP message is larger than the allowed size for an element declaration, which is only 4000 bytes! Cheers Reboot.
–
CraigOct 30 '14 at 7:36

Hi Blaise, thanks for the answer. I tried this solution with my jaxb implementation, see below. My code runs in an JEE environment and I would like to use the jaxb library available. I may check out MOXy if I do not find a solution. @javax.xml.bind.annotation.XmlSchema(namespace = "ebics.org/H003&quot;, xmlns = { @javax.xml.bind.annotation.XmlNs(prefix = "", namespaceURI = "ebics.org/H003") , @javax.xml.bind.annotation.XmlNs(prefix = "ds", namespaceURI = "w3.org/2000/09/xmldsig#") }, elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
–
WilberforceFeb 2 '11 at 19:35

Yes, I used NamespacePrefixMappiner (see code above). I now found out that my problem was related to xjc generating java code that had erroneously generated annotations with attribute namespace set to "". That forced jaxb to use "" as default namespace overiding any custom settings. I did not find out why exactly that happened but after changing the code manually All is working fine.
–
WilberforceMar 14 '11 at 18:06

1

@Wilberforce: You should have done that as an answer to your question so that we can vote it up. (Self-answering is encouraged, provided it is an answer.)
–
Donal FellowsSep 28 '11 at 8:58