1

支払い情報を含む xml ドキュメントを作成する必要があります。いくつかの名前空間があり、各タグにプレフィックスを追加する必要があります。それが私のセットアップです:

xsd:

<xs:complexType name="Document">
    <xs:sequence>
        <xs:element name="FIToFICstmrCdtTrf" type="FIToFICustomerCreditTransferV02"/>
    </xs:sequence>
</xs:complexType>
<xs:complexType name="FIToFICustomerCreditTransferV02">
    <xs:sequence>
        <xs:element name="GrpHdr" type="GroupHeader33"/>
        <xs:element maxOccurs="unbounded" minOccurs="1" name="CdtTrfTxInf" type="CreditTransferTransactionInformation11"/>
    </xs:sequence>
</xs:complexType>

xjb:

<jaxb:bindings schemaLocation="../xsd/pacs.008.001.02.xsd" node="/xs:schema">
<jaxb:bindings node="xs:complexType[@name='Document']">
  <annox:annotate>
    <annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="SCTSIBIBlkCredTrf" namespace="urn:EESCTSIBI:xsd:$SCTSIBIBlkCredTrf">
    </annox:annotate>
  </annox:annotate>
</jaxb:bindings>
<jaxb:bindings node="xs:complexType[@name='FIToFICustomerCreditTransferV02']">
  <annox:annotate>
    <annox:annotate annox:class="javax.xml.bind.annotation.XmlType" namespace="urn:iso:std:iso:20022:tech:xsd:pacs.008.001.02"/>
  </annox:annotate>
</jaxb:bindings>

生成されたクラス:

@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;

コード生成 xml:

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();
    }
}

生成されたxml:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<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">
<sw8:FIToFICstmrCdtTrf>
    <sw8:GrpHdr>
        <sw8:MsgId>MsgId</sw8:MsgId>
    </sw8:GrpHdr>
    <sw8:CdtTrfTxInf>
        <sw8:PmtId>
            <sw8:InstrId>InstrId</sw8:InstrId>
            <sw8:EndToEndId>End2End</sw8:EndToEndId>
            <sw8:TxId>TxId</sw8:TxId>
        </sw8:PmtId>
    </sw8:CdtTrfTxInf>
</sw8:FIToFICstmrCdtTrf>

xml が必要です:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<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">
<EESCTSIBI:FIToFICstmrCdtTrf xmlns="urn:iso:std:iso:20022:tech:xsd:pacs.008.001.02">
    <sw8:GrpHdr>
        <sw8:MsgId>MsgId</sw8:MsgId>
    </sw8:GrpHdr>
    <sw8:CdtTrfTxInf>
        <sw8:PmtId>
            <sw8:InstrId>InstrId</sw8:InstrId>
            <sw8:EndToEndId>End2End</sw8:EndToEndId>
            <sw8:TxId>TxId</sw8:TxId>
        </sw8:PmtId>
    </sw8:CdtTrfTxInf>
</EESCTSIBI:FIToFICstmrCdtTrf>

xjb ファイルを変更するにはどうすればよいですか?

thx 4 返信

4

0 に答える 0