HI Jennifer -
I appreciate the reply. So it looks I will have to
clone the node if I want to use the cached DOM without
directly making changes to it during the processing of
i.e Using, set objDOM = Application("CachedXMLData")
will cause the "CachedXMLData" to be altered if objDOM
is altered. Am I correct in thinking this?
--- Jennifer Phillips <jennifer(_at_)globet(_dot_)com> wrote:
Does anyone know whats the best way to cache an xml
dom in global.asa [ASP/VBScript] ?
I dont know about the best way, but the way I do it
I have a number of XML documents that are used
in my code and I did not want to load them each
instead cache it so that I can just call it once
keep resuing it.
Wise move, just be a little careful about the memory
usage of storing so
many DOM's in memory, you could end up slowing the
whole thing down rather
than speeding it up.
Once I cache it what is the best way to call is
I just set an object reference to the DOM in the
Application object, however
this does have one drawback, if you change the DOM
referenced in the
variable, you also change the cached version in the
(Since they are the same thing), if you need to
change the data in the DOM
you will have to clone it (Unless you want the
cached version updated also).
Anyway here's the code.....
I personally dont start the cache in the Globet.asa,
because my data is
updated quite often so each time its hit, it needs
to check the cache is
still fresh, so this goes into an ASP page, shouldnt
be too hard to modify
to go into the Global.asa.
' This IF checks whether we have any cached data or
we have asked to updated
if isEmpty(Application("CachedXMLData")) or _
Request("refresh") = "true" then
' load the XML document
' IMPORTANT!!!!! To be stored in the
application object it
' MUST be a FreeThreaedDOMDocument NOT a
set xml =
' Load in the XML
call loadXMLFile(xml, "C:\MyData.XML")
' Save it to the Application object
call updateAppVariable("CachedXMLData", xml)
Sub loadXMLFile(xmldoc, filename)
if not xmldoc.load(filename) then
Response.Write "Error loading the file '" _
& filename & "'.<br>"
Response.Write "Description: " & _
xmldoc.parseError.reason & "<br>"
Response.Write "Line: " & _
xmldoc.parseError.line & "<br>"
Response.Write "Line position: " _
& xmldoc.parseError.linepos & "<br>"
Sub updateAppVariable(varName, value)
if isObject(value) then
set Application(varname) = value
Application(varname) = value
Then to retrieve the DOM data....
set objDOM = Application("CachedXMLData")
If you are doing a lot of XSLT with the cached XML
data, its also good to
store the XSLT template in the application object
too since then its
pre-compiled, on the pages I've done this on,
combined with the XML caching,
I got a 5 fold performance increase.
If you have any further questions let me know.
XSL-List info and archive:
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list