需求:
value1
value2
value3
根据PROPERTYCODE 的值,获取value,赋值给java对象。
根据标签,对应,可以直接使用@XmlElement(name = "PROPERTY"),但是根据属性值,还真不知道怎么用,后来在网上找到了一个帖子,
https://my.oschina.net/zy223344/blog/727603
说明的很详细,需要使用 @XmlAnyAttribute 属性转化
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name="PROPERTYLIST")public classValueList {private List PropertyList = new ArrayList();public ListgetPropertyList() {returnPropertyList;
}
@XmlElement(name="Property")public void setPropertyList(ListpropertyList) {this.propertyList =propertyList;
}
}
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name= "Property")public classProperty {
@XmlAnyAttribute()private Map map;//每个Item的属性值
@XmlValueprivateString text;publicMap getMap() {returnmap;
}public voidsetMap(Map map) {this.map =map;
}publicString getText() {returntext;
}public voidsetText(String text) {this.text =text;
}
}
text 的值就是对应的value
使用map.get(QName.valueOf("PROPERTYCODE")) 获取test1.
若不适用QName,确实获取到的为null。