Help with XML Nodes

  • Thread starter news.microsoft.com
  • Start date
N

news.microsoft.com

Hi,

The following site describes how to loop through xml nodes in an XML DOM,
I'll post the code below as well.

http://abstractvb.com/code.asp?A=840


This works fine, but in the example all that you pipe out is the firstname
of the customer. How would you gain access to all of the customers
information from within the loop??

Many thanks,

Rick

Create an XML file similar to the following and save it as
c:\customerdata.xml.

CustomerData.xml
<customerdata>
<customer>
<firstname>Frank</firstname>
<lastname>Cuttengham</lastname>
<address>123 Developer Lane</address>
<city>Denver</city>
<state>Colorado</state>
<zip>90210</zip>
<phone>433-3453</phone>
<email>[email protected]</email>
</customer>
<customer>
<firstname>Bob</firstname>
<lastname>Michels</lastname>
<address>544 Center St.</address>
<city>Calgary</city>
<state>Alberta</state>
<zip>T2Z6S4</zip>
<phone>345-7765</phone>
<email>[email protected]</email>
</customer>
</customerdata>
In Visual Basic create a new project and add a reference to MSXML3. On Form1
copy and paste this code and then run the project.
Form1
Private Sub Form_Load()
Dim objDoc As MSXML2.DOMDocument40
Dim objNodeList As MSXML2.IXMLDOMNodeList
Dim objNode As MSXML2.IXMLDOMNode

Set objDoc = New MSXML2.DOMDocument30

If objDoc.Load("c:\customerdata.xml") Then
If Not objDoc Is Nothing Then
Set objNodeList =
objDoc.selectNodes("customerdata/customer/firstname")

If Not objNodeList Is Nothing Then

'Loop though each node in the node list
For Each objNode In objNodeList
Debug.Print objNode.Text
Next
End If
End If
End If
End Sub
The two customer's names from the XML file will be listed in your debug
window.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top