标签:php creat lis throw mys obj oid sha tag
一、xml格式
<Data>
<Row>
<MyDataSource>
<driverClassName></driverClassName>
<url></url>
<userName></userName>
<password></password>
</MyDataSource>
<MySourceSql>
</MySourceSql>
<TerminalSource>
<driverClassName></driverClassName>
<url></url>
<userName></userName>
<password></password>
</TerminalSource>
<TerminaSql>
</TerminaSql>
</Row>
</Data>
@XmlRootElement(name=
public class Data {
@XmlElement(name =
private List<Row> rowList;
@Override
public String toString() {
return "Data{" +"rowList=" + rowList +‘}‘;
}
public List<Row> getRowList() {
eturn rowList;
}
public void setRowList(List<Row> rowList) {
this.rowList = rowList;
}
}
二、
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
public static Object convertXmlStrToObject(Class clazz, String xmlStr) throws Exception {
Object xmlObject = null;
JAXBContext context = JAXBContext.newInstance(clazz);
// 进行将Xml转成对象的核心接口
Unmarshaller unmarshaller = context.createUnmarshaller();
StringReader sr = new StringReader(xmlStr);
xmlObject = unmarshaller.unmarshal(sr);
return xmlObject;
}
标签:php creat lis throw mys obj oid sha tag
原文地址:https://www.cnblogs.com/liveinpresent/p/11627493.html