Solved

Need to parse out XML using VB6

Posted on 2009-05-06
9
369 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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
 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
XSLT list item selection criteria not working 12 30
XML response optional elements 12 39
tutorial for ebay api 3 33
XML Document XPath with Namespaces 3 20
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

776 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