Solved

Need to parse out XML using VB6

Posted on 2009-05-06
9
365 Views
Last Modified: 2012-05-06
I have this simple XML file that I need to parse out.  I'm looking at the feature ID's and need to know the value of each.  I don't care about the rest of the XML.  I'm using VB6 and kinda new to XML.  I have a reference set to XML ver 4 in my project already.  Thanks!
XML.jpg
0
Comment
Question by:Dep5758
  • 5
  • 4
9 Comments
 
LVL 8

Expert Comment

by:Bob Hoffman
ID: 24320368
Try this.
    Dim oDom As New DOMDocument
   
    Dim oNodes As IXMLDOMNodeList
    Dim oNode As IXMLDOMNode
    Dim oInfoNode As IXMLDOMNode
    Dim oAttr As IXMLDOMAttribute
   
    If oDom.Load("c:\test.xml") Then
        Set oNodes = oDom.documentElement.selectNodes("hasp_info")
       
        For Each oNode In oNodes
            For Each oInfoNode In oNode.childNodes
                If oInfoNode.nodeName = "feature" Then
                  For Each oAttr In oInfoNode.Attributes
                      If oAttr.baseName = "id" Then
                          MsgBox oAttr.Text
                      End If
                  Next
                End If
            Next
        Next
   
    End If
 
0
 

Author Comment

by:Dep5758
ID: 24320491
I tried you code but the If oDom.Load statement doesn't run.  I'm passing a XML string into the oDom.Load rather reading from a file.  Any ideas?  Thanks!
0
 

Author Comment

by:Dep5758
ID: 24320522
I inserted this error statement to see why it is skipping:
Err.Raise oDom.parseError.errorCode
and I receive an  Run-time error '-2147221020(800401e4)':  "Invalid Port Number"
0
 
LVL 8

Expert Comment

by:Bob Hoffman
ID: 24320582
do you have a reference to "Microsoft XML v4.0" if your project?
Attach your XML file and I'll take a look.
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:Dep5758
ID: 24320677
yes I have a reference to the v4.0.
XML-Data.txt
0
 
LVL 8

Accepted Solution

by:
Bob Hoffman earned 500 total points
ID: 24320821
Your xml is mssing the root node. If it's not possible to add one you could read it as text into a string variable, wrap that with a root node and load the dom with .LoadXML(). See attached.
0
 

Author Comment

by:Dep5758
ID: 24320993
Could you please reattach as nothing is last post.  Thanks!
0
 
LVL 8

Expert Comment

by:Bob Hoffman
ID: 24321021
here you go
test.txt
0
 

Author Comment

by:Dep5758
ID: 24321157
That was it!  Thank you for your help!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now