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

XML文件
<?xml version="1.0"?>
<AutoUpdater>
  <DownloadAddres URL="http://6099.pqpq.net/UploadFiles/AutoUpdater.xml" />
  <URLAddres URL="http://192.168.1.113/system/update/" />
  <UpdateInfo>
    <UpdateTime Date="2009-06-12" />
    <Version Num="1.0.0.0" />
  </UpdateInfo>
  <UpdateFileList>
  </UpdateFileList>
  <RestartApp>
    <ReStart Allow="Yes" />
    <AppName Name="DownloadApp.exe" />
  </RestartApp>
</AutoUpdater>


读取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;
        }

你可能感兴趣的:(java,C++,c,xml,C#)