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 code looks like this:
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.
I figured I could, if I wanted to, create two XmlNodeLists, one with "../../Name" and one with "../../ID", but I don't know how I could For Each iterate through both a the same time or how to keep them "synched."
Is there some other way to do it?
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
I figured I could, if I wanted to, create two XmlNodeLists, one with "../../Name" and one with "../../ID", but I don't know how I could For Each iterate through both a the same time or how to keep them "synched."
Is there some other way to do it?