Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Visual Basic 6.0 Code - Reading XML

Reply
Thread Tools

Visual Basic 6.0 Code - Reading XML

 
 
Dan G.
Guest
Posts: n/a
 
      06-27-2003
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
 
Reply With Quote
 
 
 
 
Colin Mackenzie
Guest
Posts: n/a
 
      06-27-2003
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." <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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



 
Reply With Quote
 
 
 
 
Sebastian Fey
Guest
Posts: n/a
 
      06-27-2003

> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the difference between Visual Basic.NET and Visual Basic 6? Jimmy Dean Computer Support 3 07-25-2005 07:05 AM
Visual Studio .Net v.s. Visual Basic .Net? M P ASP .Net 6 08-07-2004 04:25 AM
For what use LABELS (left of the code) in Visual Basic Code? Andreas Klemt ASP .Net 3 01-14-2004 02:26 PM
eMbedded Visual Basic & Visual Studio .NET - No Longer Supported? ¢harlie MCSD 0 12-26-2003 07:23 PM
Upgrading Microsoft Visual Basic 6.0 to Microsoft Visual Basic .NET Jaime MCSD 2 09-20-2003 05:16 AM



Advertisments