我有以下代码
@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;
}
当使用jaxb marshaller时,我得到以下输出:
<?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>
如何从每个xml中移除xmlns:xsi和xml:xs并仅将其添加到根节点一次?
答案 0 :(得分:0)
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;
}