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.
The problem is, the XML document rarely changes, but the system has to load it all in every time it wants to use it.
Is there any way of creating a global XML document that is only read in once and just referenced with this function instead?
Dim oContent As New XmlDocument
oContent.Load(HttpContext.Current.Server.MapPath("/includes/content/content.xml"))
Try
Return oContent.SelectSingleNode("/xml/Contents/Content[attribute::title='" & sTitle.ToLower & "']").InnerText.Replace("<", "<").Replace(">", ">")
Catch ex As Exception
Return ""
End Try
oContent = Nothing
Thanks
Ben
-- Please mark my responses as answers if they help!
ferretneck
Member
601 Points
279 Posts
XMLDocument Load
Feb 21, 2012 03:55 PM|LINK
Hi
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.
The problem is, the XML document rarely changes, but the system has to load it all in every time it wants to use it.
Is there any way of creating a global XML document that is only read in once and just referenced with this function instead?
Dim oContent As New XmlDocument oContent.Load(HttpContext.Current.Server.MapPath("/includes/content/content.xml")) Try Return oContent.SelectSingleNode("/xml/Contents/Content[attribute::title='" & sTitle.ToLower & "']").InnerText.Replace("<", "<").Replace(">", ">") Catch ex As Exception Return "" End Try oContent = NothingThanks
Ben
Shellymn
Contributor
2600 Points
484 Posts
Re: XMLDocument Load
Feb 21, 2012 04:32 PM|LINK
You can make use of Cache object . Read the xml file from global.asax ( on Application_Start event) and cache it.
ferretneck
Member
601 Points
279 Posts
Re: XMLDocument Load
Feb 21, 2012 04:34 PM|LINK
Is there any problem using a session instead?
I guess I lied a bit when I said it's not updated regularly - it could potentially be updated every evening.
Thanks
Ben
Hua-Jun Li -...
All-Star
75950 Points
5608 Posts
Re: XMLDocument Load
Feb 23, 2012 08:20 AM|LINK
Hi,
There is difference between the Cache and session.
The Cache is open to all the users in the application. the session is open to the specific users.
If you store the xmldocument into session, it only be retrieved by the one user.
You should store it for every user.
And in the Cache , you only store once, you can get it in any place.
Please check the following link:
http://weblogs.asp.net/albertpascual/archive/2010/03/01/difference-between-asp-net-sessions-application-variables-and-cache-objects.aspx
If you have any feedback about my replies, please contact msdnmg@microsoft.com.
Microsoft One Code Framework