作者:000000 | 来源:互联网 | 2023-05-21 14:50
1> Florian Schm..:
您没有使用Linq to XML:
var doc = XDocument.Load("data.xml");
var bookNodes = doc.Descendants("book").Where(b=> b.Parent.Name == "shop");
使用常规的System.Xml:
var doc = new XmlDocument();
doc.Load("data.xml");
var bookNodes = doc.SelectNodes(@"//bookstore/book");
foreach (XmlNode item in bookNodes)
{
string title = item.SelectSingleNode("./title").InnerText;
string price = item.SelectSingleNode("./price").InnerText;
Console.WriteLine("title {0} price: {1}",title,price); //just for demo
}