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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help!!How to read this XML file using VBA or VB6

Status
Not open for further replies.

rockfido

Technical User
Apr 27, 2010
6
US
Hey guys,

Im really new to XML and actually also new to VB6...But i do need to solve the following problem. I need to read the following xml file using either VBA or VB6.0 and save the information into txt as:

Date1 Date2 Response R_ID ID1 Des1 ID2 Des3
0109 0108 This 12345 10001 HH 10002 BB
0109 0107 That 67890 2001 HH 3003 BB


My XML File:

<?xml version="1.0" encoding="iso-8859-1"?>
<ExportCR Date1="0109">
<CR Date2="0108">
<Response R_ID="12345"><![CDATA[This]]></Response>
<ID Destination="HH">10001</ID>
<ID Destination="BB">10002</ID>
</CR>
<CR Date2="0107">
<Response R_ID="67890"><![CDATA[That]]></Response>
<ID Destination="HH">2001</ID>
<ID Destination="BB">3003</ID>
</CR>
</ExportCR>

I tried like this way:
..........

SET XN=XMLDoc.selectSingleNode("ExportCR")

but how can i get the information of date1?

a=XN.*** ???

and i searched online, seems like it should be like: getAttribute, but it doesnt work in my VBA or VB6....do i need to add more reference or what should i do?


I greatly appreciate ur help!!
?????
 
What is wrong with this?
[tt] a=XN.getAttribute("Date1") 'return "0109"[/tt]
 
it works now....

but my another question....how can i get information within each CR? Should I also define CR as IXMLDOMElement? Or define CR as other type?

Thanks a lot
 
Dim odc As DOMDocument
Dim odc1 As IXMLDOMElement
Dim nde As IXMLDOMNode
Dim a As IXMLDOMElement

Set odc = New MSXML2.DOMDocument

odc.Load ("example.xml")

For Each nde In odc.SelectNodes("ExportCR")
Set a = nde.SelectSingleNode("CR")
Debug.Print a.Text

Next


--------------i could only write like this but cant make more progress....

1. In above code, it could only print information of the first CR record:
This is a bad response. 10001 10002

but how can i get the second one?

2. If I wanna get the whole information of each CR, like Date2, R_ID and Destination, how can i do it? Which kind of do loop should I use (as in above, i used:
For Each nde In odc.SelectNodes("ExportCR")
Set a = nde.SelectSingleNode("CR"))


Thank you guys so much


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top