Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Need to parse out XML using VB6

Posted on 2009-05-06
9
Medium Priority
?
378 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

650 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