Source
code for http://www.fullenergy.com/xmlwebnavigation.inc
COLOR LEGEND
| Server Side Script | |
| Client Side Script | |
| Hyperlink | |
| Include | |
| Frames | |
| Comments | |
| Object Code Link | |
| Standard HTML and Text |
<%
Const namespaceURI = "http://www.fullenergy.com/XmlWebNavigation/1.0"
Response.Buffer=False
ReDim DatabaseArrayID(0)
ReDim DatabaseArrayResultSet(0)
Function ProcessDatabase(Node)
On Error Resume Next
Set DB=Server.CreateObject("ADODB.Connection")
SQL=Node.getElementsByTagName("query").Item(0).firstChild.text
Counter=0
' response.Write sql
For Each Item In Node.getElementsByTagName("variable")
Counter=Counter+1
Select Case Item.getAttribute("source")
Case "request"
Variable = Request(Item.firstChild.text)
Case "cookie"
Variable= Request.Cookies(Item.firstChild.text)
Case "session"
Variable = Session(Item.firstChild.text)
Case Else
Exit Function
End Select
SQL=Replace(SQL, "%" & Counter, Variable)
Next
'response.Write sql
DB.Open Node.getElementsByTagName("connectionString").Item(0).firstChild.text
Set RS=DB.Execute(SQL)
If Not RS.EOF Then
NewSize=UBound(DatabaseArrayID)+1
Redim Preserve DatabaseArrayID(NewSize)
Redim Preserve DatabaseArrayResultSet(NewSize)
DatabaseArrayID(NewSize) = Node.getAttribute("id")
Set DatabaseArrayResultSet(NewSize) = RS
End If
On Error Goto 0
End Function
Function ProcessSet(Node)
If Node.getAttribute("source") = "cookie" Then
Response.Write "cookie being set -- ERROR!"
ElseIf Node.getAttribute("source") = "session" Then
name = Node.getElementsByTagName("name").Item(0).firstChild.text
value= Node.getElementsByTagName("value").Item(0).firstChild.text
Session(name)=value
End If
End Function
Function CalculateConditionResult(Source, SourceVar, TestOperation, RightOperand)
'response.Write "calc source = " & Source & "<BR>"
Select Case Source
Case "request"
LeftOperand = Request(SourceVar)
Case "cookie"
LeftOperand = Request.Cookies(SourceVar)
Case "session"
LeftOperand = Session(SourceVar)
Case Else
' good chance this is a database call
For i = 1 to UBound(DatabaseArrayID)
If(DatabaseArrayID(i) = Source) Then
On Error Resume Next
LeftOperand = CStr(DataBaseArrayResultSet(i)(SourceVar))
On Error Goto 0
End If
Next
If LeftOperand = "" Then Exit Function
End Select
'response.Write "<BR>"
'response.Write "leftopearnd = " & leftoperand & "<BR>"
'response.Write "rightoperand = " & rightoperand & "<BR>"
Select Case TestOperation
Case "equals"
Result = (LeftOperand = RightOperand)
Case "notequals"
Result = (LeftOperand <> RightOperand)
Case "greaterthan"
Result = (LeftOperand > RightOperand)
Case "lessthan"
Result = (LeftOperand < RightOperand)
Case "greaterthanorequal"
Result = (LeftOperand >= RightOperand)
Case "lessthanorequal"
Result = (LeftOperand <= RightOperand)
Case Else
Exit Function
End Select
'response.Write "result = " & result & "<BR>"
CalculateConditionResult = Result
End Function
Function ProcessUrlTarget(Node)
' Response.Write "target = " &node.text
ProcessUrlTarget = Node.text
End Function
Function ProcessNavTarget(Node)
ProcessNavTarget=XmlWebNavigate(Node.text)
End Function
Function ProcessBoolean(Node, Bool)
' Response.Write "processboolean pre = " & UCase(CStr(bool)) & " " & UCase(CStr(Node.NodeName)) & "<BR>"
If UCase(CStr(bool)) = UCase(CStr(Node.NodeName)) Then
' Response.Write "processboolean post = " & UCase(CStr(bool)) & " " & UCase(CStr(Node.NodeName)) & "<BR>"
For Each Item in Node.ChildNodes
If (Item.NodeName = "condition") Then ProcessBoolean=ProcessCondition(Item)
If (Item.NodeName = "urltarget") Then ProcessBoolean=ProcessUrlTarget(Item)
If (Item.NodeName = "navtarget") Then ProcessBoolean=ProcessNavTarget(Item)
If (Item.NodeName = "set") Then ProcessSet Item
Next
End If
End Function
Function ProcessCondition(Node)
'Response.Write "<HR NOSHADE>"
FirstResult = ""
' Response.Write "process condition top = " & Node.NodeName & "<BR>"
If (Node.NodeName <> "#text" and Node.NodeName <> "#comment") Then
ConditionResult = CalculateConditionResult(Node.getAttribute("source"), Node.getAttribute("name"), Node.getAttribute("operation"), Node.getAttribute("value"))
End If
For Each Item in Node.ChildNodes
'response.Write "condition childnode name = " & item.nodename &", conditionresult = " & conditionresult & "<BR>"
Select Case Item.NodeName
Case "true"
' response.Write "true" & "<BR>"
FirstCondition = ProcessBoolean(Item, ConditionResult)
Case "false"
' response.Write "false" & "<BR>"
FirstCondition = ProcessBoolean(Item, ConditionResult)
Case "condition"
FirstCondition = ProcessCondition(Item)
Case "set"
ProcessSet Item
Case Else
response.Write item.nodename
End Select
If FirstCondition <> "" Then
' we only use the first condition that was found true all the way
ProcessCondition = FirstCondition
Exit For
End If
Next
End Function
Function XmlWebNavigate(Location)
Set XML = Server.CreateObject("Microsoft.XMLDOM")
XML.Async = False
XML.Load(Server.MapPath(Location & ".xml"))
FirstResult = ""
' check for errors
If (XML.ParseError.ErrorCode <> 0) Then
Response.Write "<B>Error: XML Parsing Failed</B><BR>"
Response.Write XML.ParseError.Reason & "(" & xml.ParseError.ErrorCode & ")" & "<BR>"
Exit Function
End If
' validate the namespace
namespaceUsed = XML.documentElement.getAttribute("xmlns")
If (namespaceUsed <> namespaceURI) Then
Response.Write "<B>Error: Incorrect namespace used for this processor</B><BR>"
Response.Write "This processor accepts: " & namespaceURI
Response.Write ", it found: " & namespaceUsed
Response.Write "<BR>"
Exit Function
End If
' begin processing
For Each Node In XML.documentElement.childNodes
'response.Write "xmlnav: " & node.nodename & "<BR>"
If Node.NodeName = "database" Then
ProcessDatabase Node
ElseIf Node.NodeName = "set" Then
ProcessSet Node
ElseIf Node.NodeName = "condition" Then
FirstResult = ProcessCondition(Node)
' match the 1st element
If FirstResult <> "" Then Exit for
End If
Next
Set XML=Nothing
XmlWebNavigate = FirstResult
End Function
%>