c# 读取xml某个节点的值的方法

XML文件


















读取DownloadAddres 的值

public string GetDownloadAddres(string Dir)
{
string LastDownloadAddres = "";
string AutoUpdaterFileName = Dir;
if (!File.Exists(AutoUpdaterFileName))
{
return LastDownloadAddres;
}
//打开xml文件
FileStream myFile = new FileStream(AutoUpdaterFileName, FileMode.Open);
//xml文件阅读器
XmlTextReader xml = new XmlTextReader(myFile);
while (xml.Read())
{
if (xml.Name == "DownloadAddres")
{
//获取升级文档的最后一次更新日期
LastDownloadAddres = xml.GetAttribute("URL");
break;
}
}
xml.Close();
myFile.Close();
return LastDownloadAddres;
}

你可能感兴趣的:(.NET)