http://www.okajax.com/a/200911/jquery.html
链接里是Jquery的插件管理,
包含一个XML文件:
<?xml version="1.0" encoding="utf-8"?> <Resources>     <Common>       <Plugins>         <Plugin Name="cookie" Src="~/App_Scripts/jPlugin/cookie/cookie.pack.js">           <Styles>           </Styles>           <Scripts>             <Script Key="jquery" Src="~/App_Scripts/jquery.js" />           </Scripts>         </Plugin>         <Plugin Name="treeview" Src="~/App_Scripts/jPlugin/jquery-treeview/jquery.treeview.pack.js">           <Styles>             <Style Key="jquery_treeview_css" Href="~/App_Scripts/jPlugin/jquery-treeview/jquery.treeview.css" />           </Styles>           <Scripts>             <Script Key="jquery" Src="~/App_Scripts/jquery.js" />           </Scripts>         </Plugin>         <Plugin Name="autocomplete" Src="~/App_Scripts/jPlugin/jquery-autocomplete/jquery.autocomplete-bundle.pack.js">           <Styles>             <Style Key="autocomplete_css" Href="~/App_Scripts/jPlugin/jquery-autocomplete/jquery.autocomplete.css" />           </Styles>           <Scripts>             <Script Key="jquery" Src="~/App_Scripts/jquery.js" />             <Script Key="bgiframe" Src="~/App_Scripts/jPlugin/jquery-bgiframe/jquery.bgiframe.min.js" />           </Scripts>         </Plugin>       </Plugins>     </Common>     <Required>         <Scripts>           <Script Name="jdMenu"></Script>             <Script Name="hint"></Script>             <Script Name="jQueryCustomExt"></Script>             <Script Name="cookie"></Script>         </Scripts>     </Required>     <Pages>         <Page Src="~/Administration/EmployeeMgmt.aspx">             <Scripts>                 <Script Name="jTemplates"></Script>                 <Script Name="treeview"></Script>                 <Script Name="scrollTo"></Script>                 <Script Name="validate"></Script>                 <Script Name="jQueryCustomExt"></Script>                 <Script Name="autocomplete"></Script>                 <Script Name="blockUI"></Script>             </Scripts>         </Page>         <Page Src="~/ScheduleMgmt/Reschedule.aspx">             <Scripts>                 <Script Name="My97DatePicker"></Script>                 <Script Name="jQueryCustomExt"></Script>                 <Script Name="draggable_1.0"></Script>                 <Script Name="jTemplates"></Script>                 <Script Name="tab_1.0"></Script>                 <Script Name="autocomplete"></Script>                 <Script Name="spinBtn"></Script>                 <Script Name="hotkeys"></Script>                 <Script Name="datepicker"></Script>                 <Script Name="clockpick"></Script>                 <Script Name="validate"></Script>                 <Script Name="blockUI"></Script>                 <Script Name="tooltip"></Script>                 <Script Name="contextmenu"></Script>                 <Script Name="hint"></Script>                 <Script Name="jqueryMultiSelect"></Script>                 <Script Name="timePicker"></Script>             </Scripts>         </Page>     </Pages> </Resources> 

解决方案 »

  1.   

    还有一个解析资源文件using System;  using System.Collections.Generic;  using System.Linq;  using System.Text;  using System.Web.UI;  using System.Xml;  using System.Web;  using System.Web.Caching;   namespace Luna.Common  {     public class SiteConfig      {          public static XmlDocument GetResourceXml()          {              XmlDocument doc = new XmlDocument();              ContentCache contentCache = ContentCache.Instantiate();                 if (contentCache["ResourceMulit"] != null)              {                  doc = (XmlDocument)contentCache["ResourceMulit"];              }              else              {                  string file = HttpContext.Current.Server.MapPath("/App_Data/ResourceMulit.xml");                  doc.Load(file);                  CacheDependency dep = new CacheDependency(file, DateTime.Now);                  contentCache.Insert("ResourceMulit", doc, dep);              }              return doc;          }           public static void RegsiterResource()          {              XmlDocument doc = SiteConfig.GetResourceXml();               XmlNode firstNode = doc.DocumentElement.FirstChild;              XmlNodeList RequiredScripts = firstNode.FirstChild.ChildNodes;              XmlNodeList RequiredStyles = firstNode.ChildNodes[1].ChildNodes;               Page currentPage = (Page)HttpContext.Current.Handler;              RegisterResource(RequiredScripts, RequiredStyles);               XmlNode secondNode = doc.DocumentElement.ChildNodes[1];              foreach (XmlNode item in secondNode.ChildNodes)              {                                    string pageSrc = item.Attributes["Src"].Value.ToLower();                  if (currentPage.ResolveUrl(pageSrc) == HttpContext.Current.Request.Path.ToLower())                  {                      RegisterResource(item.FirstChild.ChildNodes, item.ChildNodes[1].ChildNodes);                  }              }          }            public static void RegsiterResourceKey(XmlNode node, List<string> resourceNode, List<string> removeNode)          {              if (node != null)              {                  XmlNode scriptsNodes = node.SelectSingleNode("descendant::Scripts");                   foreach (XmlNode scriptNode in scriptsNodes.ChildNodes)                  {                      if (scriptNode.Attributes["Removed"] == null)                      {                          resourceNode.Add(scriptNode.Attributes["Name"].Value);                      }                      else                      {                          removeNode.Add(scriptNode.Attributes["Name"].Value);                      }                   }              }          }           public static void RegsiterCommon()          {              XmlDocument doc = SiteConfig.GetResourceXml();                //XmlNodeList RequiredStyles = firstNode.ChildNodes[1].ChildNodes;              List<Plugin> PluginList = RegsiterCommonResource(doc);               //RegisterResource(RequiredScripts, RequiredStyles);              //Pages                XmlNode currentPageNode = GetCurrentPageNode(doc);              XmlNode RequireNode = GetRequireNode(doc);              Dictionary<string, string> scriptList = new Dictionary<string, string>();              Dictionary<string, string> styleList = new Dictionary<string, string>();               List<string> removeNode = new List<string>();              List<string> resourceNode = new List<string>();              if (currentPageNode != null)              {                  XmlAttribute isAuthenticated = currentPageNode.Attributes["IsAuthenticated"];                  if (isAuthenticated != null)                  {                       if (Convert.ToBoolean(isAuthenticated.Value) && HttpContext.Current.Request.IsAuthenticated)                      {                          RegsiterResourceKey(currentPageNode, resourceNode, removeNode);                      }                  }                  else                  {                      RegsiterResourceKey(currentPageNode, resourceNode, removeNode);                  }              }                            RegsiterResourceKey(RequireNode, resourceNode, removeNode);              List<string> filterResourceNode= resourceNode.FindAll(delegate(string node)              {                  foreach (var item in removeNode)                  {                      return node != item;                  }                  return true;              });             foreach (var item in filterResourceNode)              {                  Plugin plugin = GetCurrentPlugin(item, PluginList);                   RegisterPlugin(scriptList, styleList, plugin);              }          }           public static void RegisterPlugin(Dictionary<string, string> scriptList, Dictionary<string, string> styleList, Plugin plugin)          {              Page currentPage = (Page)HttpContext.Current.Handler;              foreach (Style style in plugin.Styles)              {                  if (!styleList.ContainsKey(style.Key))                  {                      styleList.Add(style.Key, style.Href);                      currentPage.AddCss(style.Href);                  }              }              foreach (Script script in plugin.Scripts)              {                  if (!scriptList.ContainsKey(script.Key))                  {                      scriptList.Add(script.Key, script.Src);                      currentPage.AddScript(script.Src);                  }              }              if (!scriptList.ContainsKey(plugin.Name))              {                  scriptList.Add(plugin.Name, plugin.Src);                  currentPage.AddScript(plugin.Src);              }          }           public static Plugin GetCurrentPlugin(string scriptNode, List<Plugin> PluginList)          {               foreach (Plugin plugin in PluginList)              {                  if (scriptNode == plugin.Name)                  {                      return plugin;                  }              }              return PluginList[0];          }           private static XmlNode GetRequireNode(XmlDocument doc)          {              XmlNode node = doc.DocumentElement.SelectSingleNode("descendant::Required");              return node;          }           public static XmlNode GetCurrentPageNode(XmlDocument doc)          {               Page currentPage = (Page)HttpContext.Current.Handler;              XmlNode node = doc.DocumentElement.SelectSingleNode("descendant::Pages");              foreach (XmlNode item in node.ChildNodes)              {                   string pageSrc = item.Attributes["Src"].Value.ToLower();                  if (currentPage.ResolveUrl(pageSrc) == HttpContext.Current.Request.Path.ToLower())                  {                      return item;                  }              }              return null;          }           public static List<Plugin> RegsiterCommonResource(XmlDocument doc)          {              XmlNode firstNode = doc.DocumentElement.SelectSingleNode("descendant::Common");              XmlNodeList PluginNodeList = firstNode.SelectSingleNode("descendant::Plugins").ChildNodes;               Page currentPage = (Page)HttpContext.Current.Handler;              List<Plugin> plugins = new List<Plugin>();              foreach (XmlNode item in PluginNodeList)              {                  Plugin plugin = new Plugin();                  plugin.Name = item.Attributes["Name"].Value;                  plugin.Src = currentPage.ResolveUrl(item.Attributes["Src"].Value);                                    XmlNodeList scripts = item.SelectSingleNode("descendant::Scripts").ChildNodes;                  foreach (XmlNode script in scripts)                  {                      string key = script.Attributes["Key"].Value;                      string src = currentPage.ResolveUrl(script.Attributes["Src"].Value);                      bool removed = false;                      if (script.Attributes["Removed"] != null)                      {                          removed = Convert.ToBoolean(script.Attributes["Removed"].Value);                      }                      plugin.Scripts.Add(new Script(key, src,false));                  }                  XmlNode styles = item.SelectSingleNode("descendant::Styles");                                    if (styles != null)                  {                      foreach (XmlNode style in styles.ChildNodes)                      {                          plugin.Styles.Add(new Style(style.Attributes["Key"].Value,currentPage.ResolveUrl(style.Attributes["Href"].Value)));                      }                  }                  plugins.Add(plugin);              }              return plugins;          }           private static void RegisterScript(string aa)          {              //foreach (XmlNode item in scriptsNode)              //{              //    string key = item.Attributes["Name"].Value;               //    RegisterScript(key);              //}          }           private static void RegisterResource(XmlNodeList scripts, XmlNodeList styles)          {              Page currentPage = (Page)HttpContext.Current.Handler;              foreach (XmlNode item in styles)              {                  string href = currentPage.ResolveUrl(item.Attributes["Href"].Value);                  LiteralControl control = new LiteralControl(string.Format("\n<link href=\"{0}\" rel=\"stylesheet\" type=\"text/css\" />", href));                  currentPage.Header.Controls.Add(control);              }              foreach (XmlNode item in scripts)              {                  string key = item.Attributes["Key"].Value;                  string src = currentPage.ResolveUrl(item.Attributes["Src"].Value);                  currentPage.AddScript(src);                  //currentPage.ClientScript.RegisterClientScriptInclude(currentPage.GetType(), key, src);              }           }      }  }  
      

  2.   

    文中提到以上文件(XML)可以利用asp.net 2.0的文件依赖缓存在服务器端缓存起来,然后进行解析
    求详细做法,或指导资料