我是JAXB库的新手,无法获得将@XmlAttribute添加到现有代码的解决方案。如何将属性添加到JAXB中的元素
我有具有两个元件(名称和值),如下所示的XML:
<ns4:Envelope xmlns:ns2="xyz/123" xmlns:ns3="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns4="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns6="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns5="http://www.w3.org/2001/XMLSchema" xmlns:abc="abc">
<ns4:Header>
<ns2:ID ns4:mustUnderstand="1">testId</ns2:ID>
</ns4:Header>
<ns4:Body>
<ns2:Set>
<List ns3:arrayType="abc:hash[1]">
<Struct>
<Name>Interval</Name>
<Value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:int">10</Value>
</Struct>
</List>
</ns2:Set>
</ns4:Body>
</ns4:Envelope>
在上述XML,所述的xsi:是已经越来越由JAXB自动生成类型。具有以下代码的结构类别
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Struct", propOrder = {
"name",
"value"
})
public class Struct {
@XmlElement(name = "Name", required = true)
protected String name;
@XmlElement(name = "Value", required = true)
protected Object value;
public String getName() {
return name;
}
public void setName(String value) {
this.name = value;
}
public Object getValue() {
return value;
}
public void setValue(Object value) {
this.value = value;
}
正如您所见,未在上述类中设置类型。我希望有一些规定可以根据用户定义添加类型,而不是根据数据类型生成。
我不知道我怎么可以添加属性来此Struct类,它可以添加类型为“值”元素(正如我们看到的元素的值是简单的字符串对象)