c#获取xml对应节点属性及节点内容

本文介绍了使用XmlDocument如何获取对应节点对应的属性值以及节点内容:
下面展示一些 内联代码片

// A code block
var foo = 'bar';
                XmlDocument xml = new XmlDocument();//实例化这个类
                string path = @"文件";
                    xml.Load(path);
                string xmltxt = xml.InnerXml.ToString();获取xml文本
                XmlDocument xmll = new XmlDocument();//重新实例化一个XmlDocument用来加载xml文本
                xmll.LoadXml(xmltxt);
                //GetElementsByTagName用来指定获取那个节点内容,会返回节点List集合
                XmlNodeList xnList = xmll.DocumentElement.GetElementsByTagName("patient");
                //通过这个集合下标的Attributes获取对应属性的值
                Console.WriteLine(xmlNodeList[3].Attributes["extension"].Value);

你可能感兴趣的:(xml,c#,asp.net)