Re: parsing xml
- From: hgeron <hgeron@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 17 Aug 2006 17:17:01 -0700
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
- Follow-Ups:
- Re: parsing xml
- From: Mark J. McGinty
- Re: parsing xml
- References:
- Re: parsing xml
- From: Mark J. McGinty
- Re: parsing xml
- Prev by Date: Re: UnauthorizedAccessException when using MSDTC
- Next by Date: Re: parsing xml
- Previous by thread: Re: parsing xml
- Next by thread: Re: parsing xml
- Index(es):
Relevant Pages
|
|