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;
}
}
}
}