title: Retrieve single attribute value from an xml doc element
body: <p>I have an xml document with the following structure</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;CoordinateData&gt;
    &lt;Continent name="Australia"&gt;
      &lt;Country name="Australia"&gt;
      &lt;Marker custid="1"&gt;     
          &lt;LocationName&gt;Port of Brisbane&lt;/LocationName&gt;
          &lt;Longitude&gt;153.1678&lt;/Longitude&gt;
          &lt;Latitude&gt;-27.3832&lt;/Latitude&gt;       
      &lt;/Marker&gt;
      &lt;Marker custid="1"&gt;     
          &lt;LocationName&gt;Port of Newcastle&lt;/LocationName&gt;
          &lt;Longitude&gt;151.7833&lt;/Longitude&gt;
          &lt;Latitude&gt;-32.9333&lt;/Latitude&gt;       
      &lt;/Marker&gt;  
      &lt;/Country&gt;
    &lt;/Continent&gt;
    &lt;Continent name="North America"&gt;
    &lt;Country name="Canada"&gt;
          &lt;Marker custid="2"&gt;     
              &lt;LocationName&gt;Port of Toronto&lt;/LocationName&gt;
              &lt;Longitude&gt;79.3724&lt;/Longitude&gt;
              &lt;Latitude&gt;43.633&lt;/Latitude&gt;     
          &lt;/Marker&gt;
          &lt;Marker custid="2"&gt;     
              &lt;LocationName&gt;Port of Vancouver&lt;/LocationName&gt;
              &lt;Longitude&gt;122.422&lt;/Longitude&gt;
              &lt;Latitude&gt;45.386&lt;/Latitude&gt;     
          &lt;/Marker&gt;  
      &lt;/Country&gt;
    &lt;/Continent&gt;
  &lt;/CoordinateData&gt;
  </code></pre>
  
  <p>I am trying to populate a dropdown of the continent names, retrieving only those that have elements in the xml file by accessing there name attribute and populating a list to bind to the dropdown.</p>
  
  <p>I can seem to get the syntax right I keep getting an object reference error.
  Here is my latest iteration, which also doesn't work. I am passing "Continent" to the function</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Working Function;</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Now I am trying to access the country attributes once Ive selected a continent
  This is my latest attempt, all seem to return 0 items.</p>
  
  <pre><code>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
  </code></pre>