</pre><pre name="code" class="csharp"> protected void init() { string filename = "Student.xml"; DataSet ds = new DataSet(); ds.ReadXml(filename); dataGridView1.DataSource = ds.Tables[0]; //--------指定查询-------- string name = "王亚晓"; XmlDocument doc = new XmlDocument(); doc.Load(filename); XmlNode root = doc.SelectSingleNode("student"); XmlNode target = root.ChildNodes[0]; foreach (XmlNode child in root.ChildNodes) { foreach (XmlNode grandson in child.ChildNodes) { if(grandson.Name=="name"&&grandson.InnerText==name) { target = grandson.ParentNode; } } } Console.WriteLine("name:"+target.ChildNodes[0].InnerText); Console.WriteLine("age:"+target.ChildNodes[1].InnerText); Console.WriteLine("sex"+target.ChildNodes[2].InnerText); }
//获取属性 Console.WriteLine(child.Attributes["type"].Name); Console.WriteLine(child.Attributes["type"].Value);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。