473,387 Members | 1,579 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

ASP, XML stuff...

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
%>

May 31 '06 #1
6 1489
Dirty Davey wrote:
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?


What's the problem you are encountering? i'm not going to plow through all
that code without some idea of what I'm looking for.
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
May 31 '06 #2
Sure, it's this bit:

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

How can I turn what it outputs into a table with the node names as
column headings?

Thanks for the response,

Bob Barrows [MVP] wrote:
Dirty Davey wrote:
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?


What's the problem you are encountering? i'm not going to plow through all
that code without some idea of what I'm looking for.
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


May 31 '06 #3
Without running this code, I can't really tell what it is outputting
now. It seems to be writing some td elelments to response now. I see you
using the nodename property so you know about that ... I just don't
understand what your problem is. Simply loop through the nodes, writing
the node names into the first row of the table. Then loop through the
childnodes, writing the data into the subsequent rows of the table.
Without knowing what the xml looks like, this is the best I can do.

Dirty Davey wrote:
Sure, it's this bit:

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

How can I turn what it outputs into a table with the node names as
column headings?

Thanks for the response,

Bob Barrows [MVP] wrote:
Dirty Davey wrote:
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?


What's the problem you are encountering? i'm not going to plow
through all that code without some idea of what I'm looking for.
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so
I don't check it very often. If you must reply off-line, then remove
the "NO SPAM"


--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
May 31 '06 #4
Dirty Davey wrote:
Sure, it's this bit:


Here is a short demo I whipped up that may help:

<%@ Language=VBScript %>
<%
dim xml, xmldoc, node, colnode
xml="<rows><row><col1>a</col1><col2>b</col2>" & _
"</row><row><col1>c</col1><col2>d</col2></row></rows>"
set xmldoc=createobject("msxml2.domdocument")
xmldoc.loadXML xml
set node=xmldoc.selectSingleNode("/rows/row")
Response.Write "<table border=""1"" style=""" & _
"border-collapse:collapse""><tr>"
for each colnode in node.childnodes
Response.Write "<th>" & colnode.nodename & "</th>"
next
Response.Write "</tr>"
for each node in xmldoc.documentElement.childnodes
Response.Write "<tr>"
for each colnode in node.childnodes
Response.Write "<td>" & colnode.text & "</td>"
next
Response.Write "</tr>"
next
Response.Write "</table>"

%>

There are those that maintain that using xsl transformations is the way
to go for this. If you'd like help with that, try an xml newsgroup.
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
May 31 '06 #5

"Dirty Davey" <go****@dirtydavey.com> wrote in message
news:11**********************@c74g2000cwc.googlegr oups.com...
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,


A few things.

Why are you posting the XML as Form field? Why not just post it directly:-

' Prepare the object
objHTTP.open "POST","https://www.myexternalurl.com/",false

' Set the content-type for the HTTP Request
objHTTP.setRequestHeader "Content-Type", "text/xml"

' Perform the request
objHTTP.send myXML 'Note no nasty URLEncoding

The receiving page can then load xml into a DOM directly from the request
object:-

Dim oDOM
Set oDOM = Server.CreateObject("MSXML2.DOMDocument.3.0")
oDOM.load Request

Also make sure the receiving page does this:-

Response.ContentType = "text/xml"

Now back in your code you do not need to load a DOM with the responseText
property. The responseXML property will return a parsed DOM to you. Just
be sure to test status = 200 to check that the response is ok.

As to transforming the XML in to HTML output. An alternative to
ASP/VBScript is XSLT which IMO is more suited to this task.

Taking Bob's example of a possible XML result the XSLT below will generate a
tabular output.

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="Windows-1252" />

<xsl:template match="rows">
<html>
<body>
<table>
<thead>
<tr>
<xsl:for-each select="row[1]/*">
<th><xsl:value-of select="local-name()" /></th>
</xsl:for-each>
</tr>
</thead>
<tbody>
<xsl:for-each select="row">
<tr>
<xsl:for-each select="*">
<td><xsl:value-of select="." /></td>
</xsl:for-each>
</tr>
</xsl:for-each>
</tbody>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>

Put this xsl into a file called myTransform.xsl

Here is a simple example of using this transform in your code:-

Dim oXSL
Set oXSL = Server.CreateObject("MSXML2.DOMDocument.3.0")
oXSL.async = false
oXSL.load Server.MapPath("myTransform.xsl")

objHTTP.responseXML.transformNodeToObject oXSL, Response

http://www.w3schools.com/xsl/default.asp

Anthony.


Jun 1 '06 #6
Anthony Jones wrote:

As to transforming the XML in to HTML output. An alternative to
ASP/VBScript is XSLT which IMO is more suited to this task.

Thanks, Anthony, I was hoping someone would post an xsl transformation for
this.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jun 1 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jeff Lambert | last post by:
I have this function everywhere in our SQL server 2000 stored procedures. Has anyone written a workaround function for it? I would appreciate if you could share. As you can imagine, searching the...
6
by: lkrubner | last post by:
Me and some friends are working on some PHP based templates for web pages. We've templates that look like this (simplified): <html> <head> <title> The green and blue design for carpentry...
72
by: Mel | last post by:
Are we going backwards ? (please excuse my spelling...) In my opinion an absolute YES ! Take a look at what we are doing ! we create TAGS, things like <H1> etc. and although there are tools...
2
by: Little PussyCat | last post by:
Hello, I need to be able to replace only the first occurance of a space character in a column. Reason being is the data in the column I am trying to replace seems to have umpteen space...
1
by: themf | last post by:
Hi, I'm trying to make a page that will become a part of another page, ie. included in the HTML at a particular point. How do I do this so all the stuff inside MY page remains intact, relative...
0
by: Jonathan Wilson | last post by:
Firstly, to get msvcrt.lib, install the .NET framework SDK. The version of msvcrt.lib included there is the exact same one as comes with Visual Studio ..NET 2003. There are some other things that...
7
by: +The_Taco+ | last post by:
Ok i'm kinda new to ASP.NET. I got like 4 aspx pages right now, all with there aspx.vb codebehind. Each of them need to connect on the same database, so what I want to do is to create a module or a...
9
by: collection60 | last post by:
I've been developing some Unix based shell tools. They work fine on Linux and MacOSX. I want to compile them on Win32. But I can't get hash_map to compile. I tried downloading stl (and...
5
by: Obinna | last post by:
Well I wrote this code that saved a Serialized ArrayList to disk in VB.NET and tried to read it in with another one in C#. Got some funny exception about my Assembly (can't rember exactly), what's...
20
by: Jimmy | last post by:
Hi to all python now has grown to a versatile language that can accomplish tasks for many different purposes. However, AFAIK, little is known about its ability of kernel coding. So I am...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.