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<UnitInfo> ParseOrg(string xml) { List<UnitInfo> orgs = new List<UnitInfo>(); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xml); XmlNodeList nodes = xmlDoc.GetElementsByTagName("unitinfo"); foreach (XmlNode n in nodes) { UnitInfo org = new UnitInfo(); org.jgbm = n.ChildNodes[0].InnerText; org.dwlsh = n.ChildNodes[1].InnerText; org.dwccbm = n.ChildNodes[2].InnerText; org.dwjc = n.ChildNodes[3].InnerText; org.dwqc = n.ChildNodes[4].InnerText; org.dwjp = n.ChildNodes[5].InnerText; org.dwcsbz = n.ChildNodes[6].InnerText; org.yzbm = n.ChildNodes[7].InnerText; org.dwdz = n.ChildNodes[8].InnerText; org.lxdh = n.ChildNodes[9].InnerText; org.zbsj = n.ChildNodes[10].InnerText; org.pxh = n.ChildNodes[11].InnerText; orgs.Add(org); } return orgs; }