简体   繁体   中英

how to add java jaxb marshaller meta-data to root element only?

i have the following code

@XmlAccessorType (XmlAccessType.FIELD)
private static class MyAttribute<T> {
    private String name;

    @XmlElement(name = "value")
    private T value;
 }
 @XmlRootElement(name = "duke-eport")


@XmlAccessorType (XmlAccessType.FIELD)
public class DukeDBInfo {


    @XmlElement(name = "sys-attribute")
    private List<MyAttribute<?>> sysAttribute;
}

when using jaxb marshaller with it i get the following output:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<duke-eport>
    <sys-attribute>
        <name>username</name>
        <value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string">udsds</value>
    </sys-attribute>
    <sys-attribute>
        <name>ip</name>


  <value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string">127.0.0.1</value>
</sys-attribute>
<sys-attribute>
    <name>server-date</name>
    <value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:dateTime">2015-05-19T16:23:09.595+03:00</value>
</sys-attribute>

how can i remove the xmlns:xsi and the xml:xs from each and add it only once to the root node ?

import org.w3._2001.xmlschema.Adapter1;

@XmlAccessorType (XmlAccessType.FIELD)
@XmlType(name = "myAttribute", propOrder = {
"username",
"server-date"
})
private static class MyAttribute<T> {
protected String username;
@XmlElement(type = String.class)
@XmlJavaTypeAdapter(Adapter1 .class)
@XmlSchemaType(name = "dateTime")
protected Calendar server-date;

@XmlElement(username = "value")
private T value;
}
@XmlRootElement(username = "duke-eport")

@XmlAccessorType (XmlAccessType.FIELD)
public class DukeDBInfo {


@XmlElement(username = "sys-attribute")
private List<MyAttribute<?>> sysAttribute;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM