I'm parsing through an XML document and need to get multiple values from each item. A single item in the XML looks like this:
I'm looking for records that match a particular ProviderID (in this example, = 860), so my bit of Visual Basic code looks like this (skip to the "xmlSourceList" line if you don't know VB):
This works fine for retrieving the name, but I want to retrieve the Name and the ID. My xpath knowledge is pretty basic, so I don't know if there's a better way to specify it to get both. I can't use "../../*" and get everything due to... well, it's complicated, but I need to be able to specify precisely which named values to return.
Is there a way besides "*" that I can use to specify multiple elements?
Code:
<Customer>
<ID>1043</ID>
<Name>Bob Smith</Name>
<Provider>
<ProviderID>860</ProviderID>
</Provider>
</Customer>
Code:
Dim xmlDoc As New System.Xml.XmlDocument()
'Load the file
xmlDoc.Load(AppPath() & "\Customers.xml")
Dim xmlSourceList As System.Xml.XmlNodeList
Dim xmlSourceItem As System.Xml.XmlNode
'List of items that match
xmlSourceList = xmlDoc.SelectNodes("//ProviderID[. = '860']/../../Name")
'Iterate through the list
For Each xmlSourceItem In xmlSourceList
txtDisplay.Text += vbCrLf & xmlSourceItem.InnerText
Next
Is there a way besides "*" that I can use to specify multiple elements?