?
Solved

Need to parse out XML using VB6

Posted on 2009-05-06
9
Medium Priority
?
374 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
More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

 
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

Technology Partners: 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!

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
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…
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…
Suggested Courses

777 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