C#- 操作XML
先看一个简单的实例
protected void Button3_Click(object sender, EventArgs e) { WR_DepartmentManage.DepartmentManage dm = new WR_DepartmentManage.DepartmentManage(); //string strDpetUser = dm.GetDeptUsers(TextBox1.Text); string strDpetUser = "<Users><User Name = \"818988\"/><User Name = \"818123\"/><User Name = \"811105\"/><User Name = \"8118\"/><User Name = \"519804\"/><User Name = \"519933\"/><User Name = \"519943\"/><User Name = \"519986\"/><User Name = \"9623\"/><User Name = \"519608\"/></Users>"; string result = strDpetUser.Replace("\"", "'"); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(result); XmlNode xn = xmlDoc.SelectSingleNode("Users"); XmlNodeList nodelist = xn.ChildNodes; //得到该节点的子节点 foreach (XmlNode node in nodelist) { string s = node.Attributes["Name"].Value; } }