VB and MSXML object 
Author Message
 VB and MSXML object

I am trying to write an app in VB to parse a XML file.  I
am having trouble with the Null and nextNode method.
Some of tis is related to usage of msxml but some is
probably due to my poor VB skills.

The following is a sub from the app.
There is a commented out section which works correctly and
displays what I'm after.
The other bit tries to use the nextNode method to achieve
the same thing but two problems
1)
do while child2 <> Null gives the error
Runtime error 438
"Object  doesn't support this property or method"
2)
set child2 = child.childNodes.nextNode does not move on to
the next node.

Any ideas?

ps The reason I want to use nextNode is more complicated
to explain, this code is just to demonstrate the problem.

Private Sub cmdLoad_Click()
Dim xmlstring As String
Dim root As IXMLDOMElement
Dim child As IXMLDOMNode
Dim child2 As IXMLDOMNode

    lstSynonym.Clear
    oXML.async = False
    oXML.Load (txtXMLDocument.Text)
    xmlstring = oXML.xml
    Set root = oXML.documentElement

'    This bit of code works fine
'    For Each child In root.childNodes
'        For Each child2 In child.childNodes
'            If child2.nodeName = "Name" Then
'                lstSynonym.AddItem (child2.Text)
'            End If
'        Next
'    Next

For Each child In root.childNodes
    Dim i As Integer
    i = 0
    Set child2 = child.childNodes.nextNode
    'Do While child2 <> Null
    ' the do while i < 1 statment is used because
    ' the Do While child2 <> Null does not execute
    Do While i < 1
        If child2.nodeName = "Name" Then
            lstSynonym.AddItem (child2.Text)
        End If
        ' the following command does not move onto the
        ' next node
        Set child2 = child.childNodes.nextNode
        i = i + 1
    Loop
Next

End Sub



Sun, 26 Sep 2004 18:01:02 GMT  
 VB and MSXML object
Try this instead:

For Each child2 In child.childNodes
    ...do whatever with child2...
Next

It enumerates through all childNodes of child, which I'm guessing is what
you are trying to do.

As far as your error, you're using Null incorrectly. To test an object, use
Nothing:
If oObject Is Nothing Then
    'oObject is not yet instantiated
End If


Quote:
> I am trying to write an app in VB to parse a XML file.  I
> am having trouble with the Null and nextNode method.
> Some of tis is related to usage of msxml but some is
> probably due to my poor VB skills.

> The following is a sub from the app.
> There is a commented out section which works correctly and
> displays what I'm after.
> The other bit tries to use the nextNode method to achieve
> the same thing but two problems
> 1)
> do while child2 <> Null gives the error
> Runtime error 438
> "Object  doesn't support this property or method"
> 2)
> set child2 = child.childNodes.nextNode does not move on to
> the next node.

> Any ideas?

> ps The reason I want to use nextNode is more complicated
> to explain, this code is just to demonstrate the problem.

> Private Sub cmdLoad_Click()
> Dim xmlstring As String
> Dim root As IXMLDOMElement
> Dim child As IXMLDOMNode
> Dim child2 As IXMLDOMNode

>     lstSynonym.Clear
>     oXML.async = False
>     oXML.Load (txtXMLDocument.Text)
>     xmlstring = oXML.xml
>     Set root = oXML.documentElement

> '    This bit of code works fine
> '    For Each child In root.childNodes
> '        For Each child2 In child.childNodes
> '            If child2.nodeName = "Name" Then
> '                lstSynonym.AddItem (child2.Text)
> '            End If
> '        Next
> '    Next

> For Each child In root.childNodes
>     Dim i As Integer
>     i = 0
>     Set child2 = child.childNodes.nextNode
>     'Do While child2 <> Null
>     ' the do while i < 1 statment is used because
>     ' the Do While child2 <> Null does not execute
>     Do While i < 1
>         If child2.nodeName = "Name" Then
>             lstSynonym.AddItem (child2.Text)
>         End If
>         ' the following command does not move onto the
>         ' next node
>         Set child2 = child.childNodes.nextNode
>         i = i + 1
>     Loop
> Next

> End Sub



Mon, 27 Sep 2004 00:40:49 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. How to call the Send method of MSXML.XMLHTTPRequest object more than one times

2. Problem with asynchronous HTTP posts using MSXML.DLL's XMLHTTPRequest object

3. Problem with asynchronous HTTP posts using MSXML.DLL's XMLHTTPRequest object

4. Embedding Objects with MSXML

5. referencing MSXML in ASP.NET w/VB

6. Has anyone used MSXML in VB?

7. How to use MSXML in VB?

8. XML in VB without MSXML

9. Using msxml.dll from VB 6.0

10. MSXML call failing in VB DLL in stored procedure

11. Distributing MSXML 3.0 with VB App.

12. MSXML & VB Crash

 

 
Powered by phpBB® Forum Software