I have controller.asp which parses a XML file. All http requests come to the controller.asp with a request type. (i.e All the forms' action attribute is equal to controller.asp in all pages with a hidden parameter for the request type). The controller.asp parses the XML file and based on the reqeuest type, gets a ASP Name from the XML file and transfers request to that ASP. This is the scenario.
In controller.asp, I am using the Microsoft XML DOM component to enable parsing. (Code Below). Since the XML DOM is created in the controller.asp, for every request, the DOM object is created, xml file loaded, parsed and destroyed, which is surely a performance overhead!
I am wondering if I can carry out the first two activities - (i.e Creating the XML DOM object and loading the XML file) once in the start of the application and just use this object in the controller.asp, then I am reducing the object creating and loading XML file overhead for the every request. right? Please let me know your opinions.
If right, I need some help with implementing it.
One way, is in the Application_OnStart eventhandler in global.asa file. I can create a application-level varibable set to the XML DOM object and load the XML file in the application-level variable. I can just use this application-level variable in the controller.asp to parse ! How is this implementation pattern? I have always heard and read that COM objects must not be put in Session. Considering this, can I put the XML DOM object (which is COM object) as a application level variable?
Seeking opinions!
******************************************************
<%
Dim requestType
Dim xmlDoc
dim NNPObj
dim docElement
dim nodeObj
dim docObj
dim childNode
dim rootNode
dim cNodes
requestType=request.form("requestType")
set xmlDoc=server.createobject("Microsoft.XMLDOM")
xmlDoc.async=false
dim bool
bool=xmlDoc.load(server.mappath("MyInfo.xml"))
set docElement=xmlDoc.documentElement
set cNodes= docElement.childNodes
for each nodeObj in cNodes
set NNPObj =nodeObj.attributes
if NNPObj.getNamedItem("id").nodeValue=requestType then
response.write "Request Type: "+ requestType +"<br><hr>"
response.write " <b><u>Model Type</u></b>: "+ NNPObj.getNamedItem("modelType").nodeValue +"<br><br>"
if NNPObj.getNamedItem("modelType").nodeValue="asp" then
response.write " <b><u>Processing ASP </u></b>: "+ NNPObj.getNamedItem("ASPName").nodeValue +"<br><hr>"
elseif NNPObj.getNamedItem("modelType").nodeValue="com" then
response.write "<b><u>Component Name</u></b>: "+ NNPObj.getNamedItem("componentName").nodeValue +"<br>"
response.write "<b><u>Method Name</u></b> :"+ NNPObj.getNamedItem("methodName").nodeValue +"<br>"
response.write "<b><u>Presentation Asp</u></b>: "+ NNPObj.getNamedItem("presentationAsp").nodeValue +"<br><hr>"
end if
end if
Next
%>
*****************************************************
XMl File:
<controller>
<action id="getEmployee"
modelType="asp"
ASPName="getEmployee.asp"
/>
<action id="addEmployee"
modelType="asp"
ASPName="addEmployee.asp"
/>
<action id="generateOppurunity"
modelType="com"
componentName="SANGenSoft.Oppurunity"
methodName="generateOppurunity()"
presentationAsp="confirmOppurunity.asp"
/>
<action id="showOppurunity"
modelType="com"
componentName="SANGenSoft.Oppurunity"
methodName="showOppurunity()"
presentationAsp="showOppurunity.asp"
/>
</controller>
***************************************************
global.asa
===========
<object
id="oPersist"
progid="Microsoft.FreeThre
runat="server"
scope="application"></obje
<script language="VBScript" runat="server">
Sub Application_OnStart()
oPersist.async = False
oPersist.load Server.MapPath("MyInfo.xml
End Sub
</script>
page.asp
========
<%
Dim oXML
'Setting it to the Application Scoped Variable
Set oXML = Application.StaticObjects(
%>