title: how to annotate namespace on Element jaxb xjc ann
body: <p>I need to create xml document with payments information. There are a few namespaces and it is nessecery to add prefix to each tag. That is my set up:</p>
  
  <p>xsd:</p>
  
  <pre><code>&lt;xs:complexType name="Document"&gt;
      &lt;xs:sequence&gt;
          &lt;xs:element name="FIToFICstmrCdtTrf" type="FIToFICustomerCreditTransferV02"/&gt;
      &lt;/xs:sequence&gt;
  &lt;/xs:complexType&gt;
  &lt;xs:complexType name="FIToFICustomerCreditTransferV02"&gt;
      &lt;xs:sequence&gt;
          &lt;xs:element name="GrpHdr" type="GroupHeader33"/&gt;
          &lt;xs:element maxOccurs="unbounded" minOccurs="1" name="CdtTrfTxInf" type="CreditTransferTransactionInformation11"/&gt;
      &lt;/xs:sequence&gt;
  &lt;/xs:complexType&gt;
  </code></pre>
  
  <p>xjb:</p>
  
  <pre><code>&lt;jaxb:bindings schemaLocation="../xsd/pacs.008.001.02.xsd" node="/xs:schema"&gt;
  &lt;jaxb:bindings node="xs:complexType[@name='Document']"&gt;
    &lt;annox:annotate&gt;
      &lt;annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="SCTSIBIBlkCredTrf" namespace="urn:EESCTSIBI:xsd:$SCTSIBIBlkCredTrf"&gt;
      &lt;/annox:annotate&gt;
    &lt;/annox:annotate&gt;
  &lt;/jaxb:bindings&gt;
  &lt;jaxb:bindings node="xs:complexType[@name='FIToFICustomerCreditTransferV02']"&gt;
    &lt;annox:annotate&gt;
      &lt;annox:annotate annox:class="javax.xml.bind.annotation.XmlType" namespace="urn:iso:std:iso:20022:tech:xsd:pacs.008.001.02"/&gt;
    &lt;/annox:annotate&gt;
  &lt;/jaxb:bindings&gt;
  </code></pre>
  
  <p></p>
  
  <p>generated class:</p>
  
  <pre><code>@XmlRootElement(name = "SCTSIBIBlkCredTrf", namespace = "urn:EESCTSIBI:xsd:$SCTSIBIBlkCredTrf")
  public class Document implements Serializable {
  
  private final static long serialVersionUID = 1L;
  
  @XmlElement(name = "FIToFICstmrCdtTrf", required = true)
  protected FIToFICustomerCreditTransferV02 fiToFICstmrCdtTrf;
  </code></pre>
  
  <p>code generating xml:</p>
  
  <pre><code>private void startXmlFiles(String[] args) {
      JAXBContext jaxbContext;
      File file = new File("C:\\file.xml");
  
      try {
          jaxbContext = JAXBContext.newInstance(Document.class);
          Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
          Document nroot = new Document();
  
  
          nroot.setFIToFICstmrCdtTrf(new FIToFICustomerCreditTransferV02());
          nroot.getFIToFICstmrCdtTrf().setGrpHdr(new GroupHeader33());
          nroot.getFIToFICstmrCdtTrf().getGrpHdr().setMsgId("MsgId");
          CreditTransferTransactionInformation11 CdtTrfTxInf = new CreditTransferTransactionInformation11();
          CdtTrfTxInf.setPmtId(new PaymentIdentification3());
          CdtTrfTxInf.getPmtId().setEndToEndId("End2End");
          CdtTrfTxInf.getPmtId().setInstrId("InstrId");
          CdtTrfTxInf.getPmtId().setTxId("TxId");
  
          nroot.getFIToFICstmrCdtTrf().getCdtTrfTxInf().add(CdtTrfTxInf);
  
  
  
          jaxbMarshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "urn:EESCTSIBI:xsd:$SCTSIBIBlkCredTrf SCTSIBIBlkCredTrf.xsd");
          jaxbMarshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new NamespacePrefixMapper() {
              @Override
              public String[] getPreDeclaredNamespaceUris() {
                  return new String[] { WellKnownNamespace.XML_SCHEMA_INSTANCE };
              }
  
              @Override
              public String[] getPreDeclaredNamespaceUris2() {
                  // TODO Auto-generated method stub
                  return super.getPreDeclaredNamespaceUris2();
              }
  
              @Override
              public String getPreferredPrefix(String namespaceUri, String suggestion, boolean requirePrefix) {
                  if (namespaceUri.equals(WellKnownNamespace.XML_SCHEMA_INSTANCE))
                      return "xsi";
                  if (namespaceUri.equals(WellKnownNamespace.XML_SCHEMA))
                      return "xs";
                  if (namespaceUri.equals(WellKnownNamespace.XML_MIME_URI))
                      return "xmime";
                  if (namespaceUri.equals("urn:EESCTSIBI:xsd:$SCTSIBIBlkCredTrf"))
                      return "EESCTSIBI";
                  if (namespaceUri.equals("urn:iso:std:iso:20022:tech:xsd:pacs.008.001.02"))
                      return "sw8";
                  return suggestion;
  
              }
              @Override
              public String[] getContextualNamespaceDecls() {
                  // TODO Auto-generated method stub
                  return super.getContextualNamespaceDecls();
              }
          });
  
          jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
  
          //jaxbMarshaller.marshal(nroot, file);
          jaxbMarshaller.marshal(nroot, System.out);
  
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>generated xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  &lt;EESCTSIBI:SCTSIBIBlkCredTrf xmlns:sw8="urn:iso:std:iso:20022:tech:xsd:pacs.008.001.02" xmlns:EESCTSIBI="urn:EESCTSIBI:xsd:$SCTSIBIBlkCredTrf" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:EESCTSIBI:xsd:$SCTSIBIBlkCredTrf SCTSIBIBlkCredTrf.xsd"&gt;
  &lt;sw8:FIToFICstmrCdtTrf&gt;
      &lt;sw8:GrpHdr&gt;
          &lt;sw8:MsgId&gt;MsgId&lt;/sw8:MsgId&gt;
      &lt;/sw8:GrpHdr&gt;
      &lt;sw8:CdtTrfTxInf&gt;
          &lt;sw8:PmtId&gt;
              &lt;sw8:InstrId&gt;InstrId&lt;/sw8:InstrId&gt;
              &lt;sw8:EndToEndId&gt;End2End&lt;/sw8:EndToEndId&gt;
              &lt;sw8:TxId&gt;TxId&lt;/sw8:TxId&gt;
          &lt;/sw8:PmtId&gt;
      &lt;/sw8:CdtTrfTxInf&gt;
  &lt;/sw8:FIToFICstmrCdtTrf&gt;
  </code></pre>
  
  <p></p>
  
  <p>xml expected:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  &lt;EESCTSIBI:SCTSIBIBlkCredTrf xmlns:sw8="urn:iso:std:iso:20022:tech:xsd:pacs.008.001.02" xmlns:EESCTSIBI="urn:EESCTSIBI:xsd:$SCTSIBIBlkCredTrf" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:EESCTSIBI:xsd:$SCTSIBIBlkCredTrf SCTSIBIBlkCredTrf.xsd"&gt;
  &lt;EESCTSIBI:FIToFICstmrCdtTrf xmlns="urn:iso:std:iso:20022:tech:xsd:pacs.008.001.02"&gt;
      &lt;sw8:GrpHdr&gt;
          &lt;sw8:MsgId&gt;MsgId&lt;/sw8:MsgId&gt;
      &lt;/sw8:GrpHdr&gt;
      &lt;sw8:CdtTrfTxInf&gt;
          &lt;sw8:PmtId&gt;
              &lt;sw8:InstrId&gt;InstrId&lt;/sw8:InstrId&gt;
              &lt;sw8:EndToEndId&gt;End2End&lt;/sw8:EndToEndId&gt;
              &lt;sw8:TxId&gt;TxId&lt;/sw8:TxId&gt;
          &lt;/sw8:PmtId&gt;
      &lt;/sw8:CdtTrfTxInf&gt;
  &lt;/EESCTSIBI:FIToFICstmrCdtTrf&gt;
  </code></pre>
  
  <p></p>
  
  <p>how should I change my xjb file?</p>
  
  <p>thx 4 reply</p>