JAXBContext Unmarshaller Marshaller

22 Views Asked by At

When i am doing unmarshalling and marshaling for xml file that have different name spaces i want explicitly apply name space type to each child.

Original document:

<?xml version="1.0" encoding="UTF-8"?>
<DataPDU xmlns="urn:swift:saa:xsd:saa.2.0">

    <head:AppHdr xmlns:head="urn:iso:std:iso:20022:tech:xsd:head.001.001.02"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <head:CreDt>2024-03-09T07:28:26.332+02:00</head:CreDt>
    </head:AppHdr>

    <pacs:Document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xmlns:pacs="urn:iso:std:iso:20022:tech:xsd:pacs.008.001.08">
        <pacs:MsgId>MID/5001.0/3evzg</pacs:MsgId>
    </pacs:Document>

</DataPDU>

After marshalling and unmarshalling:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<DataPDU xmlns:head="urn:iso:std:iso:20022:tech:xsd:head.001.001.02" xmlns="urn:swift:saa:xsd:saa.2.0" xmlns:pacs="urn:iso:std:iso:20022:tech:xsd:pacs.008.001.08">
    <pacs:Document>
        <pacs:MsgId>MID/5001.0/3evzg</pacs:MsgId>
    </pacs:Document>
    <head:AppHdr>
        <head:CreDt>2024-03-09T07:28:26.332+02:00</head:CreDt>
    </head:AppHdr>
</DataPDU>

My java classes:

@XmlRootElement(name = "DataPDU", namespace = "urn:swift:saa:xsd:saa.2.0")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(propOrder = {"document", "appHdr"})
public class DataPDU {
    @XmlElement(name = "AppHdr", namespace = "urn:iso:std:iso:20022:tech:xsd:head.001.001.02")
    private AppHdr appHdr;

    @XmlElement(name = "Document", namespace = "urn:iso:std:iso:20022:tech:xsd:pacs.008.001.08")
    private Document document;
}
0

There are 0 best solutions below