Note that there are some explanatory texts on larger screens.

plurals
  1. POControlling namespace prefixes in JAXB
    primarykey
    data
    text
    <p>How does jaxb determine the list of namespace prefix declarations whem marshalling an object? I used xjc to compile java classes for ebics (<a href="http://www.ebics.org/fileadmin/unsecured/specification/schema_current/ebics_xml_schema.zip" rel="noreferrer">ebics schema</a>). When I create an instance for an ebicsRequest it looks like this:</p> <pre><code> &lt;?xml version="1.0" encoding="UTF-16"?&gt; &lt;ns2:ebicsRequest xmlns:ns2="http://www.ebics.org/H003" Revision="1" Version="H003" xmlns="http://www.ebics.org/H003" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:ns4="http://www.ebics.org/S001" xmlns:ns5="http://www.ebics.org/H000"&gt; &lt;ns2:header authenticate="true"&gt; &lt;ns2:static&gt; &lt;ns2:HostID&gt;SIZBN001&lt;/ns2:HostID&gt; &lt;ns2:Nonce&gt;A5488F43223063171CA0FA59ADC635F0&lt;/ns2:Nonce&gt; &lt;ns2:Timestamp&gt;2009-08-04T08:41:56.967Z&lt;/ns2:Timestamp&gt; &lt;ns2:PartnerID&gt;EBICS&lt;/ns2:PartnerID&gt; &lt;ns2:UserID&gt;EBIX&lt;/ns2:UserID&gt; &lt;ns2:Product Language="de"&gt;EBICS-Kernel V2.0.4, SIZ/PPI&lt;/ns2:Product&gt; &lt;ns2:OrderDetails&gt; &lt;ns2:OrderType&gt;FTB&lt;/ns2:OrderType&gt; &lt;ns2:OrderID&gt;A037&lt;/ns2:OrderID&gt; &lt;ns2:OrderAttribute&gt;OZHNN&lt;/ns2:OrderAttribute&gt; &lt;ns2:StandardOrderParams/&gt; &lt;/ns2:OrderDetails&gt; &lt;ns2:BankPubKeyDigests&gt; &lt;ns2:Authentication Algorithm="RSA" Version="X002"&gt;...&lt;/ns2:Authentication&gt; &lt;ns2:Encryption Algorithm="RSA" Version="E002"&gt;...&lt;/ns2:Encryption&gt; &lt;/ns2:BankPubKeyDigests&gt; &lt;ns2:SecurityMedium&gt;0000&lt;/ns2:SecurityMedium&gt; &lt;ns2:NumSegments&gt;1&lt;/ns2:NumSegments&gt; &lt;/ns2:static&gt; &lt;ns2:mutable&gt; &lt;ns2:TransactionPhase&gt;Initialisation&lt;/ns2:TransactionPhase&gt; &lt;/ns2:mutable&gt; &lt;/ns2:header&gt; &lt;ns2:AuthSignature&gt; &lt;ds:SignedInfo&gt; &lt;ds:CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/&gt; &lt;ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/&gt; &lt;ds:Reference URI="#xpointer(//*[@authenticate='true'])"&gt; &lt;ds:Transforms&gt; &lt;ds:Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/&gt; &lt;/ds:Transforms&gt; &lt;ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/&gt; &lt;ds:DigestValue&gt;CSbjPbiNcFqSl6lCI1weK5x1nMeCH5bTQq5pedq5uI0=&lt;/ds:DigestValue&gt; &lt;/ds:Reference&gt; &lt;/ds:SignedInfo&gt; &lt;ds:SignatureValue&gt;...&lt;/ds:SignatureValue&gt; &lt;/ns2:AuthSignature&gt; &lt;ns2:body&gt; &lt;ns2:DataTransfer&gt; &lt;ns2:DataEncryptionInfo authenticate="true"&gt; &lt;ns2:EncryptionPubKeyDigest Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" Version="E002"&gt;dFAYe281vj9NB7w+VoWIdfHnjY9hNbZLbHsDOu76QAE=&lt;/ns2:EncryptionPubKeyDigest&gt; &lt;ns2:TransactionKey&gt;...&lt;/ns2:TransactionKey&gt; &lt;/ns2:DataEncryptionInfo&gt; &lt;ns2:SignatureData authenticate="true"&gt;...&lt;/ns2:SignatureData&gt; &lt;/ns2:DataTransfer&gt; &lt;/ns2:body&gt; &lt;/ns2:ebicsRequest&gt; </code></pre> <p>I have used a custom <code>NamespacePrefixMapper</code> 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 <code>NamespacePrefixMapper.getPreDeclaredNamespaceUris</code>. I have played around a lot with this class. Also I tried to use the <code>package-info.java</code> but I was not able to make jaxb use <code>"http://www.ebics.org/H003"</code> 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.</p> <p>My NamespacePrefixMapper class looks like</p> <pre><code> public class NamespacePrefixMapperImpl extends NamespacePrefixMapper implements NamespaceContext { private static final String[] EMPTY_STRING = new String[0]; private Map prefixToUri = null; private Map uriToPrefix = null; private void init(){ prefixToUri = new HashMap(); prefixToUri.put("", "http://www.ebics.org/H003" ); prefixToUri.put("ds", "http://www.w3.org/2000/09/xmldsig#" ); prefixToUri.put("xsi", "http://www.w3.org/2001/XMLSchema-instance" ); prefixToUri.put(XMLConstants.XML_NS_PREFIX, XMLConstants.XML_NS_URI ); prefixToUri.put(XMLConstants.XMLNS_ATTRIBUTE , XMLConstants.XMLNS_ATTRIBUTE_NS_URI ); uriToPrefix = new HashMap(); for(String prefix : prefixToUri.keySet()){ uriToPrefix.put(prefixToUri.get(prefix), prefix); } } @Override public String getPreferredPrefix(String namespaceUri, String suggestion, boolean requirePrefix) { if (uriToPrefix == null) init(); if (uriToPrefix.containsKey(namespaceUri)){ return uriToPrefix.get(namespaceUri); } return suggestion; } @Override public String[] getContextualNamespaceDecls() { // TODO Auto-generated method stub return EMPTY_STRING; } @Override public String[] getPreDeclaredNamespaceUris() { // TODO Auto-generated method stub return EMPTY_STRING; } @Override public String[] getPreDeclaredNamespaceUris2() { return new String [] {"", prefixToUri.get("")}; } public String getNamespaceURI(String prefix) { if (prefixToUri == null) init(); if (prefixToUri.containsKey(prefix)) { return prefixToUri.get(prefix); } else { return XMLConstants.NULL_NS_URI; } } public String getPrefix(String namespaceURI) { if (uriToPrefix == null) init(); if (uriToPrefix.containsKey(namespaceURI)){ return uriToPrefix.get(namespaceURI); } else { return null; } } public Iterator getPrefixes(String namespaceURI) { if (uriToPrefix == null) init(); List prefixes = new LinkedList(); if (uriToPrefix.containsKey(namespaceURI)){ prefixes.add(uriToPrefix.get(namespaceURI)); } return prefixes.iterator(); } } </code></pre> <p>I am using </p> <pre><code> Manifest-Version: 1.0 Ant-Version: Apache Ant 1.6.5 Created-By: 1.5.0-b64 (Sun Microsystems Inc.) Specification-Title: Java Architecture for XML Binding Specification-Version: 2.0 Specification-Vendor: Sun Microsystems, Inc. Implementation-Title: JAXB Reference Implementation Implementation-Version: 2.0.2 Implementation-Vendor: Sun Microsystems, Inc. Implementation-Vendor-Id: com.sun Extension-Name: com.sun.xml.bind Build-Id: b01 Class-Path: jaxb-api.jar activation.jar jsr173_1.0_api.jar jaxb1-impl. jar Name: com.sun.xml.bind.v2.runtime Implementation-Version: 2.0.2-b01-fcs </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload