作者chhuang (瓶水相逢)
看板C_Sharp
标题Re: [问题] 读取XML
时间Sun Sep 7 02:29:56 2008
※ 引述《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)