XmlHelper操作Xml文件
根据Xml地址得到Xml内容,可自定义缓存
XmlHelper使用教程:
//用法 /* XmlDocument xml = getXml(HttpContext.Current.Server.MapPath("~/qqq/sion.xml"), true); XmlNode node = null; if (type == "android") { node = xml.DocumentElement.SelectSingleNode("type[@name='oid']"); } * * HttpUtility.UrlPathEncode(node.Attributes["url"].Value) */XmlHelper源码
/// <summary> /// 开发团队:yunjsonTeam /// 官方主页:http://www.yunjson.com /// </summary> using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml; using System.Web; using System.Web.Caching; namespace yunjsonTeamUtil.Helper { public class XmlHelper { //用法 /* XmlDocument xml = getXml(HttpContext.Current.Server.MapPath("~/qqq/sion.xml"), true); XmlNode node = null; if (type == "android") { node = xml.DocumentElement.SelectSingleNode("type[@name='oid']"); } * * HttpUtility.UrlPathEncode(node.Attributes["url"].Value) */ /// <summary> /// 根据xml地址得到xml内容 /// </summary> /// <param name="path">绝对地址</param> /// <param name="cache">是否缓存(文件依赖)</param> /// <returns></returns> public static XmlDocument getXml(string path, bool cache) { XmlDocument xml; if (HttpRuntime.Cache[path] != null) { xml = HttpRuntime.Cache[path] as XmlDocument; return xml; } xml = new XmlDocument(); xml.Load(path); if (cache) { CacheDependency depend = new CacheDependency(path); HttpRuntime.Cache.Insert(path, xml, depend); } return xml; } } }