title: Get a list of ID Attributes from an XML File C#
body: <p>I am trying to get a list of the Service IDs from the xml file below.</p>
  <pre><code>  &lt;Settings&gt;
  &lt;SomeTag&gt;Some inner text&lt;/SomeTag&gt;
  &lt;Services ID=&quot;Downtown Location&quot;&gt;
      &lt;Service ID=&quot;22923&quot;&gt;Basic&lt;/Service&gt;
      &lt;Service ID=&quot;22926&quot;&gt;Basic + 2&lt;/Service&gt;
      &lt;Service ID=&quot;22927&quot;&gt;Basic + 3&lt;/Service&gt;
      &lt;Service ID=&quot;22928&quot;&gt;Basic + 4&lt;/Service&gt;
      &lt;Service ID=&quot;22929&quot;&gt;Basic + 5&lt;/Service&gt; 
  &lt;/Services&gt;
  &lt;MoreTags&gt;
      &lt;ATag&gt;&lt;/ATag&gt;
      &lt;ATag&gt;&lt;/ATag&gt;
      &lt;ATag&gt;&lt;/ATag&gt;
      &lt;ATag&gt;&lt;/ATag&gt;
  &lt;/MoreTags&gt;
  &lt;/Settings&gt;
  </code></pre>
  <p>I have tried several methods I found on line but each one has had some sort of problem. This was my last attempt.</p>
  <pre><code>          List&lt;string&gt; ServiceList = new List&lt;string&gt;();
              XmlDocument xdoc = new XmlDocument();
              xdoc.Load(AppDomain.CurrentDomain.BaseDirectory + @&quot;\Settings.xml&quot;);
              XmlNodeList nodes = xdoc.DocumentElement.SelectNodes(&quot;/Services/Service&quot;);
              foreach (XmlNode node in nodes)
              {
                  ServiceList.Add(node.Attributes[&quot;ID&quot;].Value);
              }
              return ServiceList; 
  </code></pre>
  <p>In this case the nodes has no items. I have tried several variations of SelectNodes but still have no items. Earlier I tried XDocument and a LINQ query. I would prefer to do it that way, but I have yet to find an example that collects the IDs.</p>