Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 387
  • Last Modified:

Need to parse out XML using VB6

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
Dep5758
Asked:
Dep5758
  • 5
  • 4
1 Solution
 
Bob HoffmanDeveloperCommented:
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
 
Dep5758Author Commented:
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
 
Dep5758Author Commented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Bob HoffmanDeveloperCommented:
do you have a reference to "Microsoft XML v4.0" if your project?
Attach your XML file and I'll take a look.
0
 
Dep5758Author Commented:
yes I have a reference to the v4.0.
XML-Data.txt
0
 
Bob HoffmanDeveloperCommented:
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
 
Dep5758Author Commented:
Could you please reattach as nothing is last post.  Thanks!
0
 
Bob HoffmanDeveloperCommented:
here you go
test.txt
0
 
Dep5758Author Commented:
That was it!  Thank you for your help!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now