Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML Recovering the Name of a Tag in VBA

Status
Not open for further replies.

Chance1234

IS-IT--Management
Jul 25, 2001
7,871
US
very very very new to all this,

Ive got the following code, all i want to do is retrieve the name of the node?tag? and its value, my xmldata is below and ideally what i want to return is the following


Type
Telephone Calls
case
343434K
date
1/4/03
description
Claim for calls
amount
34.54

etc etc ect

Sub subGetDataFromXMLFile()
Dim myXMLDoc As New DOMDocument
Dim ClaimList As IXMLDOMNodeList
Dim MyItem As IXMLDOMElement

myXMLDoc.Load ("h:\aXML.xml")
Set ClaimList = myXMLDoc.documentElement.childNodes

For Each MyItem In ClaimList
Debug.Print MyItem.Text

Next

Set myXMLDoc = Nothing
Set ClaimList = Nothing

End Sub


<?xml version=&quot;1.0&quot; ?>
- <ClaimSheet>
- <item>
<Type>Telephone Calls</Type>
<case>343434K</case>
<date>1/4/03</date>
<description>Claim for calls.</description>
<amount>34.54</amount>
</item>
- <item>
<Type>Stationary</Type>
<case>342323N</case>
<date>2/4/03</date>
<description>Claim for stationary.</description>
<amount>33.00</amount>
</item>
- <item>
<Type>Travel</Type>
<case>12323X</case>
<date>3/4/03</date>
<description>travel to case.</description>
<amount>143.00</amount>
</item>
</ClaimSheet>

 
got it !

Sub subGetDataFromXMLFile()
Dim myXMLDoc As New DOMDocument
Dim ClaimList As IXMLDOMNodeList
Dim MyItem As IXMLDOMElement
Dim MyChild As IXMLDOMElement

myXMLDoc.Load (&quot;h:\aXML.xml&quot;)
Set ClaimList = myXMLDoc.documentElement.childNodes

For Each MyItem In ClaimList
For Each MyChild In MyItem.childNodes
Debug.Print MyChild.nodeName
Debug.Print MyChild.Text
Next

Next

Set myXMLDoc = Nothing
Set ClaimList = Nothing

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top