Re: parsing xml



I tested the code with my landxml file, and it
that listed the first node, then each attribute in the first node then
ended without an error.

I think we need to call the Recurse function from main for each node.

This code should be generic enough to step through any xml file, when
we get it to work.

--
hgeron


"Mark J. McGinty" wrote:


"hgeron" <hgeron@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:3A93E4AF-572E-4350-B914-D5CC8B2C762F@xxxxxxxxxxxxxxxx
Oh, the error line was ...

For Each Att In Node.Attributes -Error Object required

Yeah, that's what I was talking about a few messages ago, after I looked at
the XML samples...

In the XML they look like this:

<something a1="aaa" a2="bbb">123456</something>

"123456" is a childNode of <something>

So you need to check that attributes isn't nothing:

If Not Node.attributes Is Nothing Then
For Each Att In Node.attributes
If MsgBox(Att.value, vbOKCancel) = vbCancel Then
Exit Function
End If
Next
Else
If MsgBox(Node.data, vbOKCancel) = vbCancel Then Exit Function
End If

-Mark




--
hgeron


"Mark J. McGinty" wrote:


"hgeron" <hgeron@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:D86CEFA0-08A6-4727-8ADC-D06632B3A911@xxxxxxxxxxxxxxxx
It halts before any msgbox at line in function marked "'ERROR- Object
Required...

Set NodeList = xmlDoc.childNodes

Should be Set NodeList = Node.childNodes



---------------------------------------------
Sub mark()
Dim xmlDoc As New MSXML2.DOMDocument50
Dim Node As IXMLDOMNode
Dim NodeList As IXMLDOMNodeList
xmlDoc.Load ("m:\xml\books.xml")
RecurseXML xmlDoc, 0
End Sub
Function RecurseXML(Node As IXMLDOMNode, Level As Long) As Boolean
Dim NodeList As IXMLDOMNodeList
Set NodeList = xmlDoc.childNodes 'ERROR- Object
Required
Dim Att As IXMLDOMAttribute
If NodeList.length = 0 Then
For Each Att In Node.Attributes
If MsgBox(Att.Value, vbOKCancel) = vbCancel Then Exit
Function
Next
Else
For Each Node In NodeList
If MsgBox(Node.XML, vbOKCancel) = vbCancel Then Exit
Function
If RecurseXML(Node, Level + 1) = False Then Exit Function
Next
End If
RecurseXML = True
End Function







--
hgeron


"Mark J. McGinty" wrote:


Sub Foo()
Dim xmlDoc As New MSXML2.DOMDocument50
xmlDoc.Load ("m:\xml\books.xml")


Oops that should be:

RecurseXML xmlDoc, 0

RecurseXML xmlDoc
End Eub









.



Relevant Pages

  • Re: parsing xml
    ... = vbCancel Then Exit Function ... Dim xmlDoc As New MSXML2.DOMDocument50 ... Function RecurseXML(Node As IXMLDOMNode, ...
    (microsoft.public.data.ado)
  • Re: parsing xml
    ... Dim xmlDoc As New MSXML2.DOMDocument50 ... Function RecurseXML(Node As IXMLDOMNode, ... = vbCancel Then Exit Function ...
    (microsoft.public.data.ado)
  • Re: parsing xml
    ... Dim xmlDoc As New MSXML2.DOMDocument50 ... Function RecurseXML(Node As IXMLDOMNode, ... = vbCancel Then Exit Function ...
    (microsoft.public.data.ado)
  • Re: parsing xml
    ... For Each Att In Node.Attributes -Error Object required ... = vbCancel Then Exit Function ... Dim xmlDoc As New MSXML2.DOMDocument50 ... Function RecurseXML(Node As IXMLDOMNode, ...
    (microsoft.public.data.ado)
  • Re: parsing xml
    ... point on the Exit Function lines, ... Dim xmlDoc As New MSXML2.DOMDocument50 ... RecurseXML xmlDoc, 0 ... Function RecurseXML(Node As IXMLDOMNode, ...
    (microsoft.public.data.ado)