I am trying to get a list of the Service IDs from the xml file below.
<Settings>
<SomeTag>Some inner text</SomeTag>
<Services ID="Downtown Location">
<Service ID="22923">Basic</Service>
<Service ID="22926">Basic + 2</Service>
<Service ID="22927">Basic + 3</Service>
<Service ID="22928">Basic + 4</Service>
<Service ID="22929">Basic + 5</Service>
</Services>
<MoreTags>
<ATag></ATag>
<ATag></ATag>
<ATag></ATag>
<ATag></ATag>
</MoreTags>
</Settings>
I have tried several methods I found on line but each one has had some sort of problem. This was my last attempt.
List<string> ServiceList = new List<string>();
XmlDocument xdoc = new XmlDocument();
xdoc.Load(AppDomain.CurrentDomain.BaseDirectory + @"\Settings.xml");
XmlNodeList nodes = xdoc.DocumentElement.SelectNodes("/Services/Service");
foreach (XmlNode node in nodes)
{
ServiceList.Add(node.Attributes["ID"].Value);
}
return ServiceList;
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.
