Abrufen einzelne Attribut-Wert aus einem xml-Dokument-element

Ich habe ein xml-Dokument mit der folgenden Struktur

<?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>

Ich versuche, füllen Sie eine dropdown-Liste der Kontinent-Namen abrufen, werden nur diejenigen Elemente in der xml-Datei durch den Zugang gibt es name-Attribut und füllen eine Liste zu binden, um das dropdown-Menü.

Ich kann scheinen, um die syntax richtig, dass ich immer ein Objekt-Verweis-Fehler.
Hier ist meine neueste iteration, die auch nicht funktioniert. Ich bin vorbei "Kontinent", um die Funktion

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

Arbeitsbedingungen Funktion;

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

Nun möchte ich den Zugriff auf die Land-Attribute sobald Ich wählte einen Kontinent
Dies ist mein neuester Versuch, alle scheinen return 0 Elemente.

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
InformationsquelleAutor dinotom | 2013-03-15
Schreibe einen Kommentar