Hi all,
I'm trying o get my head around XML and using ASP to parse documents.
I've managed to kncok together the code below to send a request to an
external server and then pop the response into a variable and format it
a bit.
What I'm trying to do is insert the data into a nice HTML table, maybe
using the node names as column headings. Has anyone got any suggestions
on how I can do this? and also, is this the best methid of performing
this task? I need it to be xbrowser compatible so I figured server side
would be the best option.
Big thanks in advance,
T
<head>
<%
Sub TraverseTree(obj)
For i = 0 to (obj.childNodes.length -1)
if obj.childNodes.item(i).nodeName <> "#text" then
set node = obj.childNodes.item(i)
TraverseTree(node)
else
response.write("<tr>")
Response.Write("<td><font color='black'><b>" &
obj.childNodes.item(i).parentNode.nodeName & "</b>, </font></td>")
Response.Write("<td><font color='red'>" & obj.childNodes.item(i).data &
"<br></font></td>")
'execute(obj.childNodes.item(i).parentNode.nodeNam e =
obj.childNodes.item(i).data)
end if
response.write("</tr>")
next
end Sub
%>
</head>
<body>
<%
' Declare the variables
dim objHTTP, myData, myXML
' Assign my XML request fragment
myXML = myXML & "<GetInfo>" & vbCrLf
myXML = myXML & " <User>" & vbCrLf
myXML = myXML & " <ID>1</ID>" & vbCrLf
myXML = myXML & " </User>" & vbCrLf
myXML = myXML & " <Period>" & vbCrLf
myXML = myXML & " <StartDate>01/01/2006</StartDate>" & vbCrLf
myXML = myXML & " <EndDate>01/06/2006</EndDate>" & vbCrLf
myXML = myXML & " </Period>" & vbCrLf
myXML = myXML & " <Authentication>" & vbCrLf
myXML = myXML & " <Username>user</Username>" & vbCrLf
myXML = myXML & " <Password>pass</Password>" & vbCrLf
myXML = myXML & " </Authentication>" & vbCrLf
myXML = myXML & "</GetInfo>" & vbCrLf
'response.write myXML & "<br />"
' Create the HTTP Object
set objHTTP = server.CreateObject("MSXML2.ServerXMLHTTP")
' Prepare the object
objHTTP.open "POST","https://www.myexternalurl.com/",false
' Set the content-type for the HTTP Request
objHTTP.setRequestHeader "Content-Type",
"application/x-www-form-urlencoded"
' Set the form variable and encode the XML fragment
myData = "requestxml=" & Server.URLEncode(myXML)
' Perform the request
objHTTP.send myData
'response.write objHTTP.responseText
dim objList
Set objList = CreateObject("Microsoft.XMLDOM")
objlist.async = true
objList.validateOnParse = true
objList.loadxml(objHTTP.responseText)
response.write("<table>")
TraverseTree(objList.documentElement)
response.write("</table>")
set objHTTP = nothing
%>