对于初学者来说,我的xml文件设置正确吗?我是使用xml数据的新手。 我已经相应地设置了我的文件。我希望能够根据我发送函数的statename参数将所有县名拉入下拉列表。
这是一个xml示例,真实文件的每个状态都以这种方式构建
<data>
<states>
<state>
<name>Delaware</name>
<counties>
<county>Kent County</county>
<county>New Castle County</county>
<county>Sussex County</county>
</counties>
</state>
</states>
</data>
我可以进入州级但不知道如何根据州名提取县。
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