469,282 Members | 1,888 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

Visual Basic 6.0 Code - Reading XML

Hi there, I'm trying out the following code in order to read in an XML
document.

Private Sub GetXML_Click()
Dim objDOMDocument As MSXML.DOMDocument
Dim root As IXMLDOMElement

Set objDOMDocument = New DOMDocument
objDOMDocument.async = False
objDOMDocument.Load "c:\temp\5000017.XML"
Set root = objDOMDocument.documentElement

For Each child In root.childnodes
MsgBox child.Text
Next
End Sub

....but, I'm getting a compile error on the first line, indicating that
it can't find the library. I'm sure it's something obvious, but I'm
not sure exactly where to go next. Can anyone offer some assistance??

Once I've gotten the XML loaded, I also need to parse the nodes and
find a specific id/name within the document. Any suggestions on how
to best achieve this????

Mucho Gracias!!!

Dan
Jul 20 '05 #1
2 17492
1/ Have you added a refererence to the Microsoft MSXML component (and has it
been installed on your machine)?
2/ Are you using the latest version (MSXML 4) if so use MSXML2.DOMDocument40
3/ best way on msxml is using

set theNode = objDOMDocument.selectSingleNode(strXpath)
for one (first matching) node
or
set theNodeSet = objDOMDocument.selectNodes(strXpath)
selectNodes for a node set (multiple matches)

strXPath is an Xpath expression describing the path to the node to be
selected

e.g.

"/root/items/item[(@id='F1') and (name='Fred')]"

If the ID is defined as a dataitem of type ID (in a DTD) then you can use
the xpath id function

"id('F1')"

Colin

"Dan G." <da********@manulife.com> wrote in message
news:38**************************@posting.google.c om...
Hi there, I'm trying out the following code in order to read in an XML
document.

Private Sub GetXML_Click()
Dim objDOMDocument As MSXML.DOMDocument
Dim root As IXMLDOMElement

Set objDOMDocument = New DOMDocument
objDOMDocument.async = False
objDOMDocument.Load "c:\temp\5000017.XML"
Set root = objDOMDocument.documentElement

For Each child In root.childnodes
MsgBox child.Text
Next
End Sub

...but, I'm getting a compile error on the first line, indicating that
it can't find the library. I'm sure it's something obvious, but I'm
not sure exactly where to go next. Can anyone offer some assistance??

Once I've gotten the XML loaded, I also need to parse the nodes and
find a specific id/name within the document. Any suggestions on how
to best achieve this????

Mucho Gracias!!!

Dan

Jul 20 '05 #2
set theNode = objDOMDocument.selectSingleNode(strXpath)
for one (first matching) node
or
set theNodeSet = objDOMDocument.selectNodes(strXpath)
selectNodes for a node set (multiple matches)


dont forget

objDOMDocument.setProperty "SelectionLanguage", "XPath"

to use XPath instead of MS pattern language
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

21 posts views Thread by CHANGE username to westes | last post: by
3 posts views Thread by pix | last post: by
2 posts views Thread by SL33PY | last post: by
5 posts views Thread by Ditoa | last post: by
5 posts views Thread by JimS | last post: by
97 posts views Thread by Master Programmer | last post: by
8 posts views Thread by Mark | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.