Parsing an XML file from classic ASP

Part of an application I work on derives some of its configuration from the contents of a global.asa file, with configuration hard-coded. I've been looking at ways of separating the configuration out to make it easier to maintain and to understand. Using a simple structure of:

<config>
 <settingname1>SettingValue</settingname1>
 <settingname2>SettingValue</settingname2>
 <settingname3>SettingValue</settingname3>
</config>

for the XML, and storing it in a file called "config.xml" with the appropriate permissions, obviously! I can then use the following code from ASP to parse this file and place the resultant information into the ASP Application object ready for use within any page:

Sub ReadAndParseXMLConfiguration()
' Called in Application_OnStart
Dim oXmlDocument
Set oXmlDocument = Server.CreateObject("Microsoft.XMLDOM")
oXmlDocument.Load(Server.MapPath("config.xml")) If oXmlDocument.parseError.errorcode <> 0 Then
Err.Raise oXmlDocument.parseError.errorcode, ,oXmlDocument.parseError.reason
End If
Dim oXmlNode
For Each oXmlNode in oXmlDocument.documentElement.childNodes
Application(oXmlNode.NodeName) = oXmlNode.Text
Next
End Sub

I've managed to reduce the size of the global.asa, make it easier for non-developers to change configuration settings. Now all I've got to do is get the code change agreed!

About Rob

I've been interested in computing since the day my Dad purchased his first business PC (an Amstrad PC 1640 for anyone interested) which introduced me to MS-DOS batch programming and BASIC.

My skillset has matured somewhat since then, which you'll probably see from the posts here. You can read a bit more about me on the about page of the site, or check out some of the other posts on my areas of interest.

No Comments

Add a Comment