0

首先,我的 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
4

0 回答 0