XMLDocument Loadhttp://forums.asp.net/t/1772150.aspx/1?XMLDocument+LoadThu, 23 Feb 2012 08:20:53 -050017721504843480http://forums.asp.net/p/1772150/4843480.aspx/1?XMLDocument+LoadXMLDocument Load <p>Hi</p> <p>I currently have the function below which I use for pulling data out of an XML file. I use this many times around the site.</p> <p>The problem is, the XML document rarely changes, but the system has to load it all in every time it wants to use it.</p> <p>Is there any way of creating a global XML document that is only read in once and just referenced with this function instead?</p> <pre class="prettyprint">Dim oContent As New XmlDocument oContent.Load(HttpContext.Current.Server.MapPath(&quot;/includes/content/content.xml&quot;)) Try Return oContent.SelectSingleNode(&quot;/xml/Contents/Content[attribute::title='&quot; &amp; sTitle.ToLower &amp; &quot;']&quot;).InnerText.Replace(&quot;&amp;lt;&quot;, &quot;&lt;&quot;).Replace(&quot;&amp;gt;&quot;, &quot;&gt;&quot;) Catch ex As Exception Return &quot;&quot; End Try oContent = Nothing</pre> <p>Thanks</p> <p>Ben</p> 2012-02-21T15:55:21-05:004843539http://forums.asp.net/p/1772150/4843539.aspx/1?Re+XMLDocument+LoadRe: XMLDocument Load <p>You can make use of Cache object . Read the xml file from global.asax ( on&nbsp;<strong>Application_Start</strong> event) and cache it.</p> <p></p> 2012-02-21T16:32:52-05:004843540http://forums.asp.net/p/1772150/4843540.aspx/1?Re+XMLDocument+LoadRe: XMLDocument Load <p>Is there any problem using a session instead?</p> <p>I guess I lied a bit when I said it's not updated regularly - it could potentially be updated every evening.</p> <p>Thanks</p> <p>Ben</p> 2012-02-21T16:34:21-05:004846717http://forums.asp.net/p/1772150/4846717.aspx/1?Re+XMLDocument+LoadRe: XMLDocument Load <p>Hi,</p> <p>There is difference between the Cache and session.</p> <p>The Cache is open to all the users in the application. the session is open to the specific users.</p> <p>If you store the xmldocument into session, it only be retrieved by the one user.</p> <p>You should store it for&nbsp;every user.</p> <p>And in the Cache , you only store once, you can get it in any place.</p> <p>Please check the following link:</p> <p><a href="http://weblogs.asp.net/albertpascual/archive/2010/03/01/difference-between-asp-net-sessions-application-variables-and-cache-objects.aspx">http://weblogs.asp.net/albertpascual/archive/2010/03/01/difference-between-asp-net-sessions-application-variables-and-cache-objects.aspx</a></p> 2012-02-23T08:20:53-05:00