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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Traversing XML Nodes 1

Status
Not open for further replies.

Swi

Programmer
Feb 4, 2002
1,966
US
I have the following code. When I run the code I get an error saying that it cannot create the IXMLDOMNODE.

Any ideas. I have this working in VB6 and was trying to convert to VBScript as I need to run it on an ASP page.

Thanks.

Code:
Dim xDoc, fso, f1
Set fso = CreateObject("Scripting.FileSystemObject")
Set xDoc = CreateObject("MSXML2.DOMDocument.6.0")
Set f1 = fso.OpenTextFile("C:\12484.txt",2,True)
xDoc.validateOnParse = False
xDoc.Load "C:\12484.cxml"
DisplayNode xDoc.childNodes, 0
f1.Close 
Set fso = Nothing
Set f1 = Nothing
Set xDoc = Nothing
MsgBox "Done!"

Sub DisplayNode(Nodes, Indent)
   Dim xNode
   Set xNode = CreateObject("MSXML2.IXMLDOMNode")
   Indent = Indent + 2

   For Each xNode In Nodes
      If xNode.nodeType = NODE_TEXT Then
         MSgbox Space(Indent) & xNode.parentNode.nodeName & ":" & xNode.nodeValue
      End If

      If xNode.hasChildNodes Then
         DisplayNode xNode.childNodes, Indent
      End If
   Next
End Sub

Swi
 
I'd comment out this line:
Set xNode = CreateObject("MSXML2.IXMLDOMNode")

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV, that worked however I changed my method a bit to further display child nodes and their attributes.

Thanks again.

Swi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top