xml file drill down

themaverick

New Member
For starters is my xml file set up correctly? I am new to using xml data.I've set my file up accordingly. I want to be able to pull all the county names into a dropdownlist based on the statename parameter i send the function.Here is an xml sample, the real file has every state it in structured in this manner\[code\]<data><states> <state> <name>Delaware</name> <counties> <county>Kent County</county> <county>New Castle County</county> <county>Sussex County</county> </counties></state></states></data>\[/code\]I can get to the state level but not sure how to extract the counties based on the statename.\[code\]Public Shared Function CountiesfromState(statename As String) As List(Of String) Dim doc As New XmlDocument() 'Load XML from the file into XmlDocument object doc.Load("StateCounties.xml") 'this needs Dim root As XmlNode = doc.DocumentElement 'Select all nodes with the statename indicated by the nodestring variable Dim nodeList As XmlNodeList = root.SelectNodes("states/state") For Each elem As XmlElement In nodeList Next Return (From node As XmlNode In nodeList Select node.InnerText).ToList()End Function\[/code\]
 
Back
Top