Visual Basic 6.0 Code - Reading XML

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dan G.

    #1

    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.DOMDocume nt
    Dim root As IXMLDOMElement

    Set objDOMDocument = New DOMDocument
    objDOMDocument. async = False
    objDOMDocument. Load "c:\temp\500001 7.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

    #2
    Re: Visual Basic 6.0 Code - Reading XML

    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.DOMDocum ent40
    3/ best way on msxml is using

    set theNode = objDOMDocument. selectSingleNod e(strXpath)
    for one (first matching) node
    or
    set theNodeSet = objDOMDocument. selectNodes(str Xpath)
    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." <dan_givlin@man ulife.com> wrote in message
    news:385b2e5f.0 306270432.61270 abe@posting.goo gle.com...[color=blue]
    > 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.DOMDocume nt
    > Dim root As IXMLDOMElement
    >
    > Set objDOMDocument = New DOMDocument
    > objDOMDocument. async = False
    > objDOMDocument. Load "c:\temp\500001 7.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[/color]


    Comment

    • Sebastian Fey

      #3
      Re: Visual Basic 6.0 Code - Reading XML

      [color=blue]
      > set theNode = objDOMDocument. selectSingleNod e(strXpath)
      > for one (first matching) node
      > or
      > set theNodeSet = objDOMDocument. selectNodes(str Xpath)
      > selectNodes for a node set (multiple matches)[/color]

      dont forget

      objDOMDocument. setProperty "SelectionLangu age", "XPath"

      to use XPath instead of MS pattern language


      Comment

      Working...