Q:

Linq to xml query not returning any values

I'm pulling an XML list of SharePoint site collection users and then trying to query the InnerXml. The InnerXml looks like this:
<Users xmlns="http://schemas.microsoft.com/sharepoint/soap/directory/"> 
<User ID="91" Name="Jane Smith" LoginName="domain1\jsmith" />
<User ID="814" Name="Brad Jones" LoginName="domain1\bjones" />
<User ID="1252" Name="Charles Johnson" LoginName="domain2\cjohnson" />
</Users>

Query is not returning anything (el is null), even though there is a user with ID 814.
XmlNode siteUsers = tempug.GetUserCollectionFromSite();
XElement root = XElement.Parse(siteUsers.InnerXml);
    IEnumerable<XElement> siteUsersElement =
        from el in root.Elements("User")
        where (string)el.Attribute("ID") == "814"
        select el;
foreach (XElement el in siteUsersElement)
Console.WriteLine("el: " + el);

root contains the InnerXml text, so I don't think the problem has anything to do with SharePoint.

A:

You're not specifying the namespace in your Elements call. Fortunately this is easy in LINQ to XML:
XNamespace ns = "http://schemas.microsoft.com/sharepoint/soap/directory/";
...
from el in root.Elements(ns + "User");

If you know that the ID attribute will always be an integer, I'd actually make that clear, and also avoid using a query expression when it doesn't help you:
// TODO: Find a nicer way of doing this; you shouldn't need to parse it again
XElement root = XElement.Parse(siteUsers.InnerXml);
var siteUserElements = root.Elements(ns + "User")
                           .Where(el => (int) el.Attribute("ID") == 814);

foreach (XElement el in siteUserElements)
{
    Console.WriteLine("el: " + el);
}

