Re: parsing xml



I made a few revisons to make it run. (see below)
I used the books.xml from MSDN... it is used a lot and gives xml for 12 books

I did not get a lot of msgboxs (only 2)
the first was the <?xml....?>
The second was the next 12 books (the remainder)
What I need to get is a message box for each element, and attibute to
sort in a table. I need to also parse the attributes because many are
put together as one (like in 3D coordinates ,x y z, space delimited as one
attribute.

----------------
Sub mark()
Dim xmlDoc As New MSXML2.DOMDocument50
Dim Node As IXMLDOMNode
Dim NodeList As IXMLDOMNodeList
xmlDoc.Load ("m:\xml\books.xml")
Set NodeList = xmlDoc.childNodes
For Each Node In NodeList
MsgBox Node.XML
Next
End Sub

--
hgeron


"Mark J. McGinty" wrote:


"hgeron" <hgeron@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:A1657E7E-72F2-47B9-AFEC-521E4ADC60F3@xxxxxxxxxxxxxxxx
MSXML5 is confusing.

There should be a simple way, once the DOM is accessed
in an Access module (VB and ADO) to

locate the root node and walk thru each and every
node, element, and attribute... but I have not been able
to figure out the MSXML keywords.

1. Set the DOM
2. find how many nodes

No need with For Each...

Dim Node As MSXML.IXMLDOMNode
Dim NodeList As MSXML.IXMLDOMNodeList
Set NodeList = Dom.childNodes
For Each Node In NodeList
[...]
Next

3. for each node ; msgbox the node

You could be clicking Ok for a long time! :-)

4. find how many elements
5. for each element ; msgbox the element

I'm not sure how the concept of elements (as opposed to nodes) applies. A
node has a ChildNodes collection and an Attributes collection. You would
have to recurse each node with ChildNodes.length > 0.

6. find how many attributes
7. for each attribute ; msgbox the attribute

Dim Attribute As MSXML.IXMLDOMAttribute
For Each Attribute In Node.Attributes
[...]
Next

One sub routine should read any XML, right?
Of course depending on the responses, you could program
the correct followup, but why wouldn't this work...

Impossible to even speculate without seeing your code. Does it throw any
errors? Have you stepped through it in the debugger and examined the
object[s] state[s] at each step.


I can't make it work. Does anyone out there work with this?

I do, surely thousands of others do as well. Note that all object name
examples above assume MSXML 2.0, the library prefix will have to be
adjusted, perhaps some object/interface names as well (but I think all of
them I mentioned are valid in later versions.)


-Mark


Harrell Geron






--
hgeron



.



Relevant Pages

  • Re: Add CommandBar WENN EditorType != Word
    ... Dim myOlApp As Outlook.Application ... Set myOlApp = CreateObject ... MsgBox "na, du inspector gadget!" ... ' End With ...
    (microsoft.public.de.outlook)
  • Re: Add CommandBar WENN EditorType != Word
    ... Dim mnuFile As Office.CommandBarPopup ... Set Bars = Application.ActiveInspector.CommandBars ... MsgBox "na, du inspector gadget!" ... ' End With ...
    (microsoft.public.de.outlook)
  • Re: Cancel Printing Except Q
    ... Dim myArr As Variant ... MsgBox "Don't print it" ... Dave Peterson wrote: ...
    (microsoft.public.excel.programming)
  • Re: VB and local area network
    ... Dim FixedInfoSize As Long ... Dim pAddrStr As Long ... MsgBox "Node type: Broadcast" ... IP_ADAPTER_INFO contains a linked list of adapter entries. ...
    (microsoft.public.vb.general.discussion)
  • Re: Reading in outside file
    ... I've put in some MsgBox "Test" values to check where exactly the process ... It opens the file, but then crashes before it gets to the next line. ... 'This method will open the external .xls file and read in the DFR Groups. ... Dim lastRow As Long 'Used to hold the value of last row on the sheet. ...
    (microsoft.public.excel.programming)