public static LoginInfo ParseLogin(string xml) { LoginInfo loginInfo = new LoginInfo(); List<UnitInfo> orgs = new List<UnitInfo>(); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xml); loginInfo.Result = Convert.ToInt32(xmlDoc.GetElementsByTagName("result")[0].InnerText); XmlNode userNode = xmlDoc.GetElementsByTagName("userinfo")[0]; UserInfo user = new UserInfo(); user.ryxm = userNode.ChildNodes[0].InnerText; user.yhm = userNode.ChildNodes[0].InnerText; XmlNodeList unitNodes = xmlDoc.GetElementsByTagName("unitinfo"); foreach (XmlNode n in unitNodes) { UnitInfo org = new UnitInfo(); org.jgbm = n.ChildNodes[1].InnerText; org.dwjc = n.ChildNodes[0].InnerText; org.dwqc = n.ChildNodes[0].InnerText; orgs.Add(org); loginInfo.RoleList += n.ChildNodes[6].InnerText + ","; loginInfo.Role = n.ChildNodes[6].InnerText.Split(','); } loginInfo.UnitList = orgs; loginInfo.User = user; return loginInfo; }
public static List<UserInfo> ParseUser(string xml) { List<UserInfo> users = new List<UserInfo>(); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xml); XmlNodeList nodes = xmlDoc.GetElementsByTagName("userinfo"); foreach (XmlNode n in nodes) { UserInfo user = new UserInfo(); user.jgbm = n.ChildNodes[0].InnerText; user.rylsh = n.ChildNodes[1].InnerText; user.ryxm = n.ChildNodes[2].InnerText; user.yhm = n.ChildNodes[3].InnerText; user.yhmm = n.ChildNodes[4].InnerText; user.xb = n.ChildNodes[5].InnerText; user.bgdh = n.ChildNodes[6].InnerText; user.yddh = n.ChildNodes[7].InnerText; user.email = n.ChildNodes[8].InnerText; user.csrq = n.ChildNodes[9].InnerText; user.zw = n.ChildNodes[10].InnerText; user.rzsj = n.ChildNodes[11].InnerText; user.pxh = n.ChildNodes[12].InnerText; users.Add(user); } return users; }