XML Tree Walker Problem

W

Wayne Wengert

I am trying to run the web page example given in the VSNET 2003 Help for
"Introduction to the DOM". I saved the example as an aspx page but when I
run it I get the following error which I don't understand. Any pointers will
be appreciated.

Wayne

=========== Error =====================

Compiler Error Message: BC30289: Statement cannot appear within a method
body. End of method assumed.

Source Error:


Line 8: <%
Line 9:
Line 10: function attribute_walk(node)
Line 11:
Line 12: For i=1 to indent

=====================================
The sample page is as follows:

=========== Code From Help Example ===============
<%@LANGUAGE=VBScript%>
<html>
<head>
<title>Tree walk test - VBScript</title>
</head><body>
<%

function attribute_walk(node)

For i=1 to indent
Response.Write("&nbsp;")
Next
For Each attrib In node.attributes
Response.Write("|--")
Response.Write(attrib.nodeTypeString)
Response.Write(":")
Response.Write(attrib.name)
Response.Write("--")
Response.Write(attrib.nodeValue)
Response.Write("<br />")
Next
end function


function tree_walk(node)
dim nodeName

indent=indent+2

For Each child In node.childNodes
For i=1 to indent
Response.Write("&nbsp;")
Next
Response.Write("|--")
Response.Write(child.nodeTypeString)
Response.Write("--")
If child.nodeType<3 Then
Response.Write(child.nodeName)
Response.Write("<br />")
End If
If (child.nodeType=1) Then
If (child.attributes.length>0) Then
indent=indent+2
attribute_walk(child)
indent=indent-2
End If
End If
If (child.hasChildNodes) Then
tree_walk(child)
Else
Response.Write child.text
Response.Write("<br />")
End If
Next

indent=indent-2

end function

xmlFile=Request.Form("fileURI")

Dim root
Dim xmlDoc
Dim child
Dim indent

indent=0

Set xmlDoc = CreateObject("Msxml2.DOMDocument.4.0")
xmlDoc.async = False
xmlDoc.validateOnParse=False
xmldoc.resolveExternals = false
xmlDoc.load(xmlFile)
If xmlDoc.parseError.errorcode = 0 Then
'Walk from the root to each of its child nodes:
Response.Write("<pre>")
tree_walk(xmlDoc)
Response.Write("</pre>")
Else
%>
<h1>XML Parsing - DOM Tree Walk Demo</h1>
<form id="location" method="post" action="">
<input type="text" name="fileURI" maxlength="255" size="20" id="XMLurl" />
<br />
<input type="submit" name="submit" value="submit" />
</form>
<% End If%>
</body></html>
 
K

Ken Cox [Microsoft MVP]

Hi Wayne,

That code is for Active Server Pages (ASP) not ASP.NET. What extension do
you have on your webform file?

Ken
 
W

Wayne Wengert

When I try to run it as an asp page I get the following error:

Microsoft VBScript runtime error '800a01ad'

ActiveX component can't create object: 'msxml2.DOMDocument.5.0'

/WalkNodes.asp, line 75



Wayne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top