定制jaxb绑定

定制jaxb绑定,jaxb,Jaxb,下面是使用jaxb生成的xml 有人能建议一种覆盖方法来完全消除xmlns:ns3、xmlns:ns4和ns3:type吗 <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ipsa:Address xmlns:ipsa="http://IPSA/IPSACIM/"> <ContMed_ID xmlns:ns3="http://www.w3.org/2001/XMLSchema-instance

下面是使用jaxb生成的xml 有人能建议一种覆盖方法来完全消除xmlns:ns3、xmlns:ns4和ns3:type吗

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ipsa:Address xmlns:ipsa="http://IPSA/IPSACIM/">
    <ContMed_ID xmlns:ns3="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns4="http://www.w3.org/2001/XMLSchema" ns3:type="ns4:int">1</ContMed_ID>
    <ContactType xmlns:ns3="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns4="http://www.w3.org/2001/XMLSchema" ns3:type="ns4:int">2</ContactType>
    <Priority xmlns:ns3="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns4="http://www.w3.org/2001/XMLSchema" ns3:type="ns4:int">3</Priority>
    <InventoryLastModified xmlns:ns3="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns4="http://www.w3.org/2001/XMLSchema" ns3:type="ns4:int">5</InventoryLastModified>
    <Flag xmlns:ns3="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns4="http://www.w3.org/2001/XMLSchema" ns3:type="ns4:int">4</Flag>
    <Street xmlns:ns3="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns4="http://www.w3.org/2001/XMLSchema" ns3:type="ns4:int">6</Street>
    <City xmlns:ns3="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns4="http://www.w3.org/2001/XMLSchema" ns3:type="ns4:int">7</City>
    <State xmlns:ns3="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns4="http://www.w3.org/2001/XMLSchema" ns3:type="ns4:int">8</State>
    <PostCode xmlns:ns3="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns4="http://www.w3.org/2001/XMLSchema" ns3:type="ns4:int">9</PostCode>
    <Country xmlns:ns3="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns4="http://www.w3.org/2001/XMLSchema" ns3:type="ns4:int">10</Country>
    <Flag xmlns:ns3="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns4="http://www.w3.org/2001/XMLSchema" ns3:type="ns4:int">11</Flag>
    <InventoryLastModified xmlns:ns3="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns4="http://www.w3.org/2001/XMLSchema" ns3:type="ns4:int">12</InventoryLastModified>
</ipsa:Address>

1.
2.
3.
5.
4.
6.
7.
8.
9
10
11
12

您可以使用
@XmlSchema
包级注释:

套餐信息

@XmlSchema(xmlns={
    @XmlNs(prefix="ipsa", namespaceURI="http://IPSA/IPSACIM/"),
    @XmlNs(prefix="xsi", namespaceURI="http://www.w3.org/2001/XMLSchema-instance"),
    @XmlNs(prefix="xs", namespaceURI="http://www.w3.org/2001/XMLSchema")
})    
package your.package;


import javax.xml.bind.annotation.*;
package your.package;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;

public class Demo {

    public static void main(String[] args) throws Exception {
        JAXBContext jc = JAXBContext.newInstance(Address.class);

        Address address = new Address();
        address.setContactMedID(1);
        address.setContactType(1);

        Marshaller marshaller = jc.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.marshal(address, System.out);
    }

}
地址

package your.package;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name="Address", namespace="http://IPSA/IPSACIM/")
public class Address {

    private Object contactMedID;
    private Object contactType;

    @XmlElement(name="ContMed_ID")
    public Object getContactMedID() {
        return contactMedID;
    }

    public void setContactMedID(Object contactMedID) {
        this.contactMedID = contactMedID;
    }

    @XmlElement(name="ContactType")
    public Object getContactType() {
        return contactType;
    }

    public void setContactType(Object contactType) {
        this.contactType = contactType;
    }

}
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:Address xmlns:ns2="http://IPSA/IPSACIM/">
    <ContMed_ID xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:int">1</ContMed_ID>
    <ContactType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:int">1</ContactType>
</ns2:Address>
演示

@XmlSchema(xmlns={
    @XmlNs(prefix="ipsa", namespaceURI="http://IPSA/IPSACIM/"),
    @XmlNs(prefix="xsi", namespaceURI="http://www.w3.org/2001/XMLSchema-instance"),
    @XmlNs(prefix="xs", namespaceURI="http://www.w3.org/2001/XMLSchema")
})    
package your.package;


import javax.xml.bind.annotation.*;
package your.package;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;

public class Demo {

    public static void main(String[] args) throws Exception {
        JAXBContext jc = JAXBContext.newInstance(Address.class);

        Address address = new Address();
        address.setContactMedID(1);
        address.setContactType(1);

        Marshaller marshaller = jc.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.marshal(address, System.out);
    }

}
输出

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ipsa:Address xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ipsa="http://IPSA/IPSACIM/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <ContMed_ID xsi:type="xs:int">1</ContMed_ID>
    <ContactType xsi:type="xs:int">1</ContactType>
</ipsa:Address>

1.
1.
在包信息类上不带@XmlSchema的输出

package your.package;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name="Address", namespace="http://IPSA/IPSACIM/")
public class Address {

    private Object contactMedID;
    private Object contactType;

    @XmlElement(name="ContMed_ID")
    public Object getContactMedID() {
        return contactMedID;
    }

    public void setContactMedID(Object contactMedID) {
        this.contactMedID = contactMedID;
    }

    @XmlElement(name="ContactType")
    public Object getContactType() {
        return contactType;
    }

    public void setContactType(Object contactType) {
        this.contactType = contactType;
    }

}
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:Address xmlns:ns2="http://IPSA/IPSACIM/">
    <ContMed_ID xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:int">1</ContMed_ID>
    <ContactType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:int">1</ContactType>
</ns2:Address>

1.
1.

您可以使用
@XmlSchema
包级注释:

套餐信息

@XmlSchema(xmlns={
    @XmlNs(prefix="ipsa", namespaceURI="http://IPSA/IPSACIM/"),
    @XmlNs(prefix="xsi", namespaceURI="http://www.w3.org/2001/XMLSchema-instance"),
    @XmlNs(prefix="xs", namespaceURI="http://www.w3.org/2001/XMLSchema")
})    
package your.package;


import javax.xml.bind.annotation.*;
package your.package;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;

public class Demo {

    public static void main(String[] args) throws Exception {
        JAXBContext jc = JAXBContext.newInstance(Address.class);

        Address address = new Address();
        address.setContactMedID(1);
        address.setContactType(1);

        Marshaller marshaller = jc.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.marshal(address, System.out);
    }

}
地址

package your.package;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name="Address", namespace="http://IPSA/IPSACIM/")
public class Address {

    private Object contactMedID;
    private Object contactType;

    @XmlElement(name="ContMed_ID")
    public Object getContactMedID() {
        return contactMedID;
    }

    public void setContactMedID(Object contactMedID) {
        this.contactMedID = contactMedID;
    }

    @XmlElement(name="ContactType")
    public Object getContactType() {
        return contactType;
    }

    public void setContactType(Object contactType) {
        this.contactType = contactType;
    }

}
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:Address xmlns:ns2="http://IPSA/IPSACIM/">
    <ContMed_ID xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:int">1</ContMed_ID>
    <ContactType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:int">1</ContactType>
</ns2:Address>
演示

@XmlSchema(xmlns={
    @XmlNs(prefix="ipsa", namespaceURI="http://IPSA/IPSACIM/"),
    @XmlNs(prefix="xsi", namespaceURI="http://www.w3.org/2001/XMLSchema-instance"),
    @XmlNs(prefix="xs", namespaceURI="http://www.w3.org/2001/XMLSchema")
})    
package your.package;


import javax.xml.bind.annotation.*;
package your.package;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;

public class Demo {

    public static void main(String[] args) throws Exception {
        JAXBContext jc = JAXBContext.newInstance(Address.class);

        Address address = new Address();
        address.setContactMedID(1);
        address.setContactType(1);

        Marshaller marshaller = jc.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.marshal(address, System.out);
    }

}
输出

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ipsa:Address xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ipsa="http://IPSA/IPSACIM/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <ContMed_ID xsi:type="xs:int">1</ContMed_ID>
    <ContactType xsi:type="xs:int">1</ContactType>
</ipsa:Address>

1.
1.
在包信息类上不带@XmlSchema的输出

package your.package;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name="Address", namespace="http://IPSA/IPSACIM/")
public class Address {

    private Object contactMedID;
    private Object contactType;

    @XmlElement(name="ContMed_ID")
    public Object getContactMedID() {
        return contactMedID;
    }

    public void setContactMedID(Object contactMedID) {
        this.contactMedID = contactMedID;
    }

    @XmlElement(name="ContactType")
    public Object getContactType() {
        return contactType;
    }

    public void setContactType(Object contactType) {
        this.contactType = contactType;
    }

}
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:Address xmlns:ns2="http://IPSA/IPSACIM/">
    <ContMed_ID xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:int">1</ContMed_ID>
    <ContactType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:int">1</ContactType>
</ns2:Address>

1.
1.