Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie trying to do ASP Classic XML project 1

Status
Not open for further replies.

HisServant

Technical User
Oct 9, 2009
2
ZA
Hi,
I'm currently busy with a project, having never done XML before... big learning curve for me.
Maybe I'm just not cut out for this whole development thing, but I'm trying and currently failing.
Please could someone point out what I'm doing wrong?
Thanks in advance!!!!
The code I've got to work from to make up the XML file is:

'--------------------------------------------------------------------------
'DB Connection Settings
'--------------------------------------------------------------------------
Application("DSN_TIMEOUT") = (objxmldom.selectSingleNode("/STARTINGXML/XMLPROJECT_DSN/@timeout").text)
Application("XMLPROJECT_UID") = (objxmldom.selectSingleNode("/STARTINGXML/XMLPROJECT_DSN/XMLPROJECT_DB/@uid").text)
Application("XMLPROJECT_PWD") = (objxmldom.selectSingleNode("/STARTINGXML/XMLPROJECT_DSN/XMLPROJECT_DB/@pwd").text)
Application("XMLPROJECT_DATASOURCE") = (objxmldom.selectSingleNode("/STARTINGXML/XMLPROJECT_DSN/XMLPROJECT_DB/@datasource").text)
Application("XMLPROJECT_CATALOG") = (objxmldom.selectSingleNode("/STARTINGXML/XMLPROJECT_DSN/XMLPROJECT_DB/@db").text)

'--------------------------------------------------------------------------
' Application Built Setting (DO NOT EDIT)
'--------------------------------------------------------------------------
Domain = LCase((objxmldom.selectSingleNode("/STARTINGXML/DOMAIN/@name").text))
PostBackDomain = LCase((objxmldom.selectSingleNode("/STARTINGXML/POSTBACK_DOMAIN/@name").text))
AppPath = LCase((objxmldom.selectSingleNode("/STARTINGXML/APP_PATH/@path").text))
Application("URLSERVER") = Domain + AppPath

'--------------------------------------------------------------------------
'STARTINGXMLurable My Project Settings
'--------------------------------------------------------------------------
Application("XMLPROJECT_NAME") = (objxmldom.selectSingleNode("/STARTINGXML/@name").text)
Application("SERVERID") = (objxmldom.selectSingleNode("/STARTINGXML/@id").text)
Application("XMLPROJECT_HOME_URL") = (objxmldom.selectSingleNode("/STARTINGXML/XMLPROJECT_HOME_URL/@url").text)
Application("SHOW_PENDING_DEPOSITS")= (objxmldom.selectSingleNode("/STARTINGXML/SHOW_PENDING_DEPOSITS/@enabled").text)
Application("SHOW_SPECIAL_OFFERS") = (objxmldom.selectSingleNode("/STARTINGXML/SHOW_SPECIAL_OFFERS/@enabled").text)
Application("SHOW_ADMIN_EVENTS") = (objxmldom.selectSingleNode("/STARTINGXML/SHOW_ADMIN_EVENTS/@enabled").text)
'--------------------------------------------------------------------------
'Logging Settings
'-------------------------------------------------------------------------------------
Application("ENABLE_LOGGING") = (objxmldom.selectSingleNode("/STARTINGXML/LOGFILE/@enabled").text)
if Application("ENABLE_LOGGING") then
Application("LOGFILE") = (objxmldom.selectSingleNode("/STARTINGXML/LOGFILE/@path").text)
end if

'--------------------------------------------------------------------------
'Supported Languages
'-------------------------------------------------------------------------------------
dim fs : set fs = Server.CreateObject("Scripting.FileSystemObject")
dim langList()
dim x : x = 0
for x = 0 to (objxmldom.selectNodes("/STARTINGXML/SUPPORTEDLANGUAGES").length-1)
if (LCase(objxmldom.selectNodes("/STARTINGXML/SUPPORTEDLANGUAGES/@enabled").item(x).text)) then
dim arrLanguage : arrLanguage = split(objxmldom.selectNodes("/STARTINGXML/SUPPORTEDLANGUAGES/@name").item(x).text,",")
dim strLanguage : strLanguage = arrLanguage(0) 'Language code in position 1 will be the file that is used 'objxmldom.selectNodes("/STARTINGXML/SUPPORTEDLANGUAGES/@name").item(x).text
dim file : file = AppPath & "\common\xml\XMLPROJECT_" & strLanguage & ".xml"
dim LangAvail : LangAvail = fs.FileExists (Server.MapPath(file))
if (LangAvail) then
set oXmlDomApp = server.CreateObject("MSXML2.FreeThreadedDOMDocument.4.0")
oXmlDomApp.Load(Server.MapPath(file))
set Application("XML_" & arrLanguage(0)) = oXmlDomApp
set oXmlDomApp = nothing
redim preserve langList(x)
langList(x) = objxmldom.selectNodes("/STARTINGXML/SUPPORTEDLANGUAGES/@name").item(x).text
end if
end if
next
Application("LANGLIST") = langList
set fs = nothing
end if
set objxmldom = nothing
end function

function getAppXml(str)
dim Language, arrSubLang
dim arrLangList : arrLangList = Application("LANGLIST")
dim foundLang : foundLang = false
dim MainDialect : MainDialect = ""
dim i : i = 0
dim a : a = 0
for i = 0 to UBound(arrLangList)
redim arrSubLang(UBound(arrLangList)-1)
arrSubLang = Split(arrLangList(i),",")
for a = 0 to UBound(arrSubLang)
if (arrSubLang(a) = str) then
a = UBound(arrSubLang)
i = UBound(arrLangList)
UsedLang = arrSubLang(0)
Language = "XML_" & arrSubLang(0)
foundLang = true
end if
next
next
if (not(foundLang)) then
redim MainDialect(UBound(Split(str,"-")))
MainDialect = Split(str,"-")
for i = 0 to UBound(arrLangList)
redim arrSubLang(UBound(arrLangList)-1)
arrSubLang = Split(arrLangList(i),",")
for a = 0 to UBound(arrSubLang)
if (arrSubLang(a) = MainDialect(0)) then
a = UBound(arrSubLang)
i = UBound(arrLangList)
UsedLang = arrSubLang(0)
Language = "XML_" & arrSubLang(0)
foundLang = true
end if
next
next
end if
if (not(foundLang)) then
Language = "XML_en"
UsedLang = "en"
end if
on error resume next
set getAppXml = Application(Language)
if (err.number <> 0) then
Language = "XML_en"
UsedLang = "en"
set getAppXml = Application(Language)
end if
end function

The XML I've come up with is this:
<STARTINGXML name="XMLPROJECT" id="10">
<APP_PATH path="C:\XMLPROJECT\"></APP_PATH>
<DOMAIN name="XMLPROJECT"></DOMAIN>
<LOGFILE enabled="true" path="/XMLPROJECT/ver24/logs/"></LOGFILE>
<XMLPROJECT_DSN timeout="10000">
<XMLPROJECT_DB datasource="DRIVER={MySQL ODBC 3.51 Driver}" db="omegasun" pwd="surfing123" uid="root"></XMLPROJECT_DB>
</XMLPROJECT_DSN>
<XMLPROJECT_HOME_URL url="/XMLPROJECT/default.asp"></XMLPROJECT_HOME_URL>
<POSTBACK_DOMAIN name="XMLPROJECT"></POSTBACK_DOMAIN>
<SHOW_ADMIN_EVENTS enabled="true"></SHOW_ADMIN_EVENTS>
<SHOW_PENDING_DEPOSITS enabled="true"></SHOW_PENDING_DEPOSITS>
<SHOW_SPECIAL_OFFERS enabled="true"></SHOW_SPECIAL_OFFERS>
<SUPPORTEDLANGUAGES enabled="true" name="en">0</SUPPORTEDLANGUAGES>
</STARTINGXML>
 
[1] This combination occurence is certain an error.
>dim MainDialect : MainDialect = ""
>redim MainDialect(UBound(Split(str,"-")))
>MainDialect = Split(str,"-")
Simpy put it like this would be just fine.
[tt]dim MainDialect[/tt]
[tt]MainDialect = Split(str,"-")[/tt]

[2]This combination of occurence is doubtful and ambiguous.
>dim Language, arrSubLang
>redim arrSubLang(UBound(arrLangList)-1)
>arrSubLang = Split(arrLangList(i),",")
Why ubound()-1? Even though it is contingent to special construction of arrLangList, redim and then assign again its value with right-hand-side split() is lacking meaningful consequence. Simpy assign to it by the split() suffice.
[tt]arrSubLang = Split(arrLangList(i),",")[/tt]

[3] Your file variable contains eventually forward slash and backslash. It can be processed but it is introducing some doubt to it. Better replace backslash by forward before passing it to server.mappath().

[4] You modify the loop variable a and i in the body. If you want to early exit the two loops, there is always the statement "exit for" at your disposal.

[5] The rest, I suppose all the objects are properly established. I have no comments to make.
 
Thank you so much for answering! I'll let you know how it goes!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top