Visual Basic 6.0 Code - Reading XML

Discussion in 'XML' started by Dan G., Jun 27, 2003.

  1. Dan G.

    Dan G. Guest

    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
    Dan G., Jun 27, 2003
    #1
    1. Advertising

  2. 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." <> wrote in message
    news:...
    > 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
    Colin Mackenzie, Jun 27, 2003
    #2
    1. Advertising


  3. > 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
    Sebastian Fey, Jun 27, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas Klemt
    Replies:
    3
    Views:
    3,094
    Brian W
    Jan 14, 2004
  2. M P
    Replies:
    6
    Views:
    547
    Joe Fallon
    Aug 7, 2004
  3. Stewart
    Replies:
    1
    Views:
    521
    Ken Cox [Microsoft MVP]
    Feb 24, 2006
  4. Anthony Moss

    visual basic from visual C++

    Anthony Moss, Dec 16, 2003, in forum: C++
    Replies:
    1
    Views:
    286
    Aggro
    Dec 16, 2003
  5. hunkgym
    Replies:
    1
    Views:
    1,982
    =?Utf-8?B?TGVvbiBNYXluZQ==?=
    Oct 30, 2006
Loading...

Share This Page