日期:2014-05-20 浏览次数:20851 次
<?xml version="1.0" encoding="utf-8" ?>
<Ips>
<ip>221.7.213.111</ip>
<ip>221.7.213.122</ip>
</Ips>
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(context.Server.MapPath("config.xml"));
xmlDoc.SelectSingleNode("");
//var ss in xmlDoc
mlDoc.SelectSingleNode("/Ips/ip[text()='221.7.213.111']");
linq版
XDocument xdoc = null;
using (var sr = System.IO.File.OpenText("config.xml"))
{
xdoc = XDocument.Load(sr);
}
var result = xdoc.Descendants("ip").FirstOrDefault(ip => ip.Value == "221.7.213.111");
XDocument root = XDocument.Load("test.xml");
IEnumerable address = from el in root.Elements("Ips").Elements("ip")
select el;