解析后台返回的XML

前端之家收集整理的这篇文章主要介绍了解析后台返回的XML前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
public class ParseXML{
public Map parseXMl(String xml)throws Exception{
Map UserListMap = new HashMap();
List userList = new ArrayList();
Document document = null;
try {
document = DocumentHelper.parseText(xml);
Element rootElt = document.getRootElement();
List UserEleList = rootElt.elements("UserNumber");
User user = null;
for (Element userEle : UserEleList) {
user = new User();
int userId = Integer.parseInt(userEle.attributeValue("userid"));
String userName = userEle.attributeValue("username");
String userPass = userEle.attributeValue("userPass");
user.setUserId(userId);
user.setUserName(userName);
user.setUserPass(userPass);
userList.add(user);
}
UserListMap.put("list",userList);
return UserListMap;
}catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
}
原文链接:https://www.f2er.com/xml/299002.html

猜你在找的XML相关文章