|
-
Nov 6th, 2002, 11:11 AM
#1
Thread Starter
Junior Member
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" />
-
Nov 6th, 2002, 12:51 PM
#2
Addicted Member
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
-
Nov 9th, 2002, 02:05 AM
#3
PowerPoster
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|