xml的讀取


<?xml version="1.0" encoding="gb2312"?>
<Update>
  <Url>123</Url>
  <File>UpdateXml1.xml</File>
  <MainEXE>TestMainUpdate.exe</MainEXE>
  <Verson>1.0.1.2017021</Verson>
  <FtpUserID>User_DownLoad</FtpUserID>
  <FtpPassword>123123</FtpPassword>
</Update>

            XmlDocument XmlUrlDoc = new XmlDocument();
            XmlUrlDoc.Load("UpdateUrl.xml");
            XmlNode UrlList = XmlUrlDoc.SelectSingleNode("Update");
            foreach (XmlNode UrlNode in UrlList)
            {
                if (UrlNode.Name == "Url")
                    UpdateXmlUrl = UrlNode.InnerText;
                if (UrlNode.Name == "File")
                    UpdateXmlFile = UrlNode.InnerText;
                if (UrlNode.Name == "MainEXE")
                    MainEXE = UrlNode.InnerText;
                if (UrlNode.Name == "Verson")
                    Verson = UrlNode.InnerText;
                if (UrlNode.Name == "FtpUserID")
                    FtpUserID = UrlNode.InnerText;
                if (UrlNode.Name == "FtpPassword")
                    FtpPassword = UrlNode.InnerText;
            }

<?xml version="1.0" encoding="gb2312" ?> 
<Update>
  <Content>
    <Verson>17.05.10.01</Verson>
    <Log>配置文件更新</Log>
    <DownLoad>Config_person.xml</DownLoad>
    <DownLoad>Config_person.xml</DownLoad>
  </Content>
  <Content>
    <Verson>17.05.10.02</Verson>
    <Log>配置文件更新</Log>
    <DownLoad>Config_person.xml</DownLoad>
    <DownLoad>Config_person.xml</DownLoad>
    <DownLoad>Config_person.xml</DownLoad>
  </Content>
</Update>

                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(stream);
                XmlNodeList ContentNodeList = xmlDoc.GetElementsByTagName("Content");

                foreach (XmlNode node in ContentNodeList)
                {
                    XmlNodeList VersonNodeList = ((XmlElement)node).GetElementsByTagName("Verson");
                    ServVerson = VersonNodeList[0].InnerText;

                    XmlNodeList LogNodeList = ((XmlElement)node).GetElementsByTagName("Log");
                    ServLog = LogNodeList[0].InnerText;
                    XmlNodeList FileNodeList = ((XmlElement)node).GetElementsByTagName("DownLoad");
                    for (int i = 0; i < FileNodeList.Count; i++)
                    {
                          //
                    } 
 
                }



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章