次の構造のxmlドキュメントがあります
<?xml version="1.0" encoding="utf-8" ?>
<CoordinateData>
<Continent name="Australia">
<Country name="Australia">
<Marker custid="1">
<LocationName>Port of Brisbane</LocationName>
<Longitude>153.1678</Longitude>
<Latitude>-27.3832</Latitude>
</Marker>
<Marker custid="1">
<LocationName>Port of Newcastle</LocationName>
<Longitude>151.7833</Longitude>
<Latitude>-32.9333</Latitude>
</Marker>
</Country>
</Continent>
<Continent name="North America">
<Country name="Canada">
<Marker custid="2">
<LocationName>Port of Toronto</LocationName>
<Longitude>79.3724</Longitude>
<Latitude>43.633</Latitude>
</Marker>
<Marker custid="2">
<LocationName>Port of Vancouver</LocationName>
<Longitude>122.422</Longitude>
<Latitude>45.386</Latitude>
</Marker>
</Country>
</Continent>
</CoordinateData>
大陸名のドロップダウンにデータを入力しようとしています。名前属性にアクセスし、ドロップダウンにバインドするリストにデータを入力して、xmlファイルに要素があるものだけを取得します。
オブジェクト参照エラーが発生し続けるので、構文が正しいように見えます。これが私の最新のイテレーションですが、これも機能しません。関数に「大陸」を渡します
Public Shared Function GetContinentList(ByVal nodestring As String) As List(Of String)
Dim doc As New XmlDocument()
doc.Load(Hosting.HostingEnvironment.MapPath(xmlfilepath_InjectLocation))
Dim list As List(Of String) = (From attribute As XmlAttribute In doc.DocumentElement(nodestring).Attributes() Select (attribute("name").Value)).ToList()
Return list
End Function
仕事関数;
Public Shared Function GetContinents() As List(Of String)
Dim doc As New XmlDocument()
doc.Load(Hosting.HostingEnvironment.MapPath(XmlfilepathInjectLocation))
Return (From node As XmlNode In doc.SelectNodes("//Continent/@name") Select node.InnerText).ToList()
End Function
大陸を選択したら、国の属性にアクセスしようとしています。これは私の最新の試みであり、すべて0個のアイテムが返されるようです。
Public Shared Function GetContinentSubItems(ByVal continentname As String) As List(Of String)
Dim doc As New XmlDocument()
doc.Load(Hosting.HostingEnvironment.MapPath(XmlfilepathInjectLocation))
Return (From node As XmlNode In doc.SelectNodes("///Country/@name") Where doc.SelectSingleNode("CoordinateData/Continent").Attributes("name").Value = continentname Select node.InnerText.ToList()
End Function