日期:2014-05-17 浏览次数:20720 次
public static void GetAllValue() { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load("..\\..\\test.xml"); XmlNodeList xnList = xmlDoc.DocumentElement.SelectNodes("//item/item/item"); foreach (XmlNode item in xnList) { Console.WriteLine(item.InnerText); } } public static void GetAllValueById(string id) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load("..\\..\\test.xml"); XmlNodeList xnList = xmlDoc.DocumentElement.SelectNodes("//item/item/item[@id='" + id + "']"); foreach (XmlNode item in xnList) { Console.WriteLine(item.InnerText); } }
------解决方案--------------------
XmlDocument xml = new XmlDocument();
xml.Load("file");
xml.Attribute["id"] ="target" ;
2.
xml.SelectSingleNode("节点名").InnerText;
方法很多。