看板 C_Sharp 關於我們 聯絡資訊
※ 引述《kenshinn (子凌(b))》之銘言: : 無意戰 : 但像這種問題我建議還是用 XmlDocument 來解決就好了 : 一旦用到了 XDocument, linq 等等,就讓程式的可攜性下降了 : 以目前 .Net Framework 3.5 還不普及的情況下 : Console 或 Window AP 的程式都還是用 2.0 就好了 : 順便提一下上面的寫法在 2.0 用 XmlDocument 來實作的方法: : XmlDocument xmlDoc = new XmlDocument(); : xmlDoc.Load(@"XMLFile.xml"); : XmlNodeList nodes = : xmlDoc.SelectNodes("/root/test[@mid=1 and @enble=TRUE]/modle"); : foreach(XmlElement element in nodes) : { : MessageBox.Show(element.InnerText); : } LINQ to XML 也是可以用 XPATH...效率不見得差多少... XDocument xd = XDocument.Load(@"XMLFile.xml"); var q = from x in xd.XPathSelectElements("//root/test[@mid=1 and @enble='TRUE']/modle") select x.Value; foreach (string s in q) { MessageBox.Show(s); } -- 瓶水相逢.Net http://www.dotblogs.com.tw/chhuang/ 我的 Live Writer Plugin - 插入博客來商品資訊 http://www.dotblogs.com.tw/chhuang/archive/2008/05/11/3926.aspx -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.62.84.89 ※ 編輯: chhuang 來自: 61.62.84.89 (09/07 02:30)