加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

读取XML文件

发布时间:2020-12-16 00:27:01 所属栏目:百科 来源:网络整理
导读:string path = System.AppDomain.CurrentDomain.BaseDirectory + "Config/Page.xml"; if (!File.Exists(path)) { return; } //载入页面设置(读取XML文件) XmlDocument xmlDoc = new XmlDocument(); try { xmlDoc.Load(path); if (xmlDoc == null) { return; }
string path = System.AppDomain.CurrentDomain.BaseDirectory + "Config/Page.xml"; if (!File.Exists(path)) { return; } //载入页面设置(读取XML文件) XmlDocument xmlDoc = new XmlDocument(); try { xmlDoc.Load(path); if (xmlDoc == null) { return; } XmlNodeList nodes = xmlDoc.SelectNodes("/PageCache/Page"); string name = string.Empty; int time = 0; foreach (XmlNode node in nodes) { name = "/" + node.Attributes["Name"].Value.ToString().TrimStart('/').ToLower(); //XML 文件节点名为Name的值,如果第一个位置没有“/”则添加,如果有,则忽略。 time = Shove._Convert.StrToInt(node.Attributes["CacheTime"].Value,0); //取节点名为CacheTime的值 if (string.IsNullOrEmpty(name)) { return; } _Settings.Add(name,time); } } catch (Exception ex) { SitePublicFunction.RecordError(ex); } finally { xmlDoc = null; }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读