Question: I have this XML:

```
<?xml version="1.0" encoding="utf-8"?>
<!-- Report generated by xxx -->
<report AppKey="stuffs" AppId="123">
  <physician name="AAA BBB">
     ....
     <services>
       <service id="1" diagnostic="345" />
       <service id="2" diagnostic="253" />
       <service id="3" diagnostic="585" />
     ....
     </services>
  </physician>
</report>

```

and this c# code

```
XmlDocument doc = new XmlDocument();
doc.Load(file);
XmlNodeList xnList = doc.SelectNodes("/report/physician/services/*");

```

My problem is that the xnList is always empty, I tried with `"/report/*"` which return 0, tried with `"/report/physician/*"` which returns the same, only `"*"` returns the entire xml file. What I want to do is to select every `<service>` and then get their attributes. I cant seem to find a way to get every service element, because my queries always return nothing.

Answer: 
Can you use `LINQtoXML`? In that case it should be as simple as:

```
var doc = XDocument.Load(file);
XNamespace ns = "http://www.cnas.ro/siui/2.0";
var nodes = doc.Root.Element(ns + "physician")
                        .Element(ns + "services")
                            .Elements(ns + "service");

```

You can also use `Descendants` which will take the matching nodes regardless of their position in the tree, like this:

```
var nodes = doc.Root.Descendants(ns + "service");

```

Either way, you will get an `IEnumerable<XElement>` that you can easily map.

N.B. remember to add `using System.Xml.Linq;` in your directives.

**UPDATE:**

For mapping to the attributes, it is a matter of opinions... I would go like this:

```
var services = from n in nodes
               select new
                   {
                       Id = n.Attribute("id").Value, 
                       Diagnostic = n.Attribute("diagnostic").Value
                   };

```

`services` will be an `IEnumerable<AnonymousType>` which you can then iterate on:

```
foreach (var service in services)
{
    Console.WriteLine(service.Id + " - " + service.Diagnostic);
}

```
This should select all service elements, no matter where they are in the file:

```
XmlNodeList xnList = doc.SelectNodes("//service");

```

Click [here](http://www.w3schools.com/xpath/xpath_syntax.asp) to find more XPath expressions