我的xml低于
<?xml version="1.0" encoding="UTF-8"?>
<employee siteId="1">
<name>john</name>
<age>36</age>
</employee>
我想使用siteId
获取itemReader
(属性值)的值。我能够成功阅读name
和age
子元素。我不知道如何获得siteId
的价值。请帮忙。谢谢!
答案 0 :(得分:0)
您可以通过在课堂上指定@XmlAttribute(name =&#34; siteId&#34;)来读取siteId属性值,请在下面找到示例
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "employee")
public class Employee {
private int siteId;
private String name;
private int age;
@XmlAttribute(name = "siteId")
public int getSiteId() {
return siteId;
}
public void setSiteId(int siteId) {
this.siteId= siteId;
}
@XmlElement(name = "age")
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@XmlElement
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}