Results 1 to 3 of 3

Thread: Need to get value of XML Attribute in VB 6

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2002
    Posts
    16

    Question Need to get value of XML Attribute in VB 6

    Hi

    I have the following snippet of XML code. I need to get ahold of the attribute value for AddressStateTC. How do I do this in VB6. I know how to get a hold of all of the element values but the attribute value is eluding me.

    Thanks In Advance


    - <Address>
    <AddressKey>1</AddressKey>
    <AddressTypeCode tc="901">MAILING</AddressTypeCode>
    <Line1>1 Baghdad Road</Line1>
    <City>Paris</City>
    <AddressState>France</AddressState>
    <AddressStateTC tc="799" />

  2. #2
    Addicted Member
    Join Date
    Aug 2000
    Location
    Pennsylvania, USA
    Posts
    168
    See http://www.vbforums.com/showthread.p...hreadid=211504 , where you posted the thread in the ASP forum.
    Wydok

    "It would appear that we have reached the limits of what it is possible to achieve with computer technology, although one should be careful with such statements, as they tend to sound pretty silly in 5 years."

    -John Von Neumann ca. 1949

  3. #3
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Here is a small example. However, the key to pulling out values from a DOM Document is to know where you are at in the tree (context node).

    Code:
    Option Explicit
    Private xmlSource As DOMDocument
    
    Private Sub Command1_Click()
        MsgBox AttributeVal("id")
    End Sub
    
    Private Function AttributeVal(ByVal sAttribute As String)
        Dim xmlAttr As IXMLDOMAttribute
        Set xmlAttr = xmlSource.selectSingleNode("//MESSAGE").Attributes.getNamedItem(sAttribute)
        If Not xmlAttr Is Nothing Then
            AttributeVal = xmlAttr.Text
        End If
    End Function
    
    Private Sub Form_Load()
        Set xmlSource = New DOMDocument
        xmlSource.loadXML "<TEST><MESSAGE id='5'/></TEST>"
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width