10 回答

TA貢獻(xiàn)1951條經(jīng)驗(yàn) 獲得超3個(gè)贊
class Persion{
String name;
int age;
@XmlAttribute
public String getName() {return name};
public void setName(...){...}
@XmlAttribute
public String getAge(){return age};
public void setAge(...){...};
}
String xml = "<?xml version=\"1.0\">";
ByteArrayInputStream inStream = new ByteArrayInputStream(xml.getBytes());
JAXBContext jc = JAXBContext.newInstance(Persion.class);
StreamSource xml = new StreamSource(inputStream);
Unmarshaller unmarshaller = jc.createUnmarshaller();
JAXBElement je1 = unmarshaller.unmarshal(xml, pclass);
Persion persion = je1.getValue();
通過(guò)jaxb解析xml字符串生成對(duì)象
添加回答
舉報(bào)