Q:

Cant figure out XMLNamespace in my Linq to XML query

Format of XML from webservice:
<Data xmlns="http://www.mywebservice.com/schema/data">
  <Record>
       <PCI>
            <FNAME>Random</FNAME>
            <LNAME>Guy</LNAME>
            <BIO />
       </PCI>
  </Record>
</Data>

My Linq-to-XML query:
XNamespace xns = "http://www.mywebservice.com/schema/data";
var Records = from Record in userInfo. Descendants(userInfoNamespace + "Record")
        select new
        {
           fname = Record. Element(xns + "FNAME").Value,
        };

This query fails.  When in debug mode i click Records, then Results View to see if it contains anything.  It just gives me a Object Reference not set to instance of object
if I do this:
select new
{
    Record,
}

all just returns all of the xml, so I know the Descendants method is correctly reading the xml
I've searched for answers but I cant find out whats going on.  Thanks for the help! 

A:

I think the problem is that you're looking for FNAME using Element, when it's an element of PCI, not of Record.   Either use Descendant or find it as an Element of PCI. 
Also, it looks like both userinfoNamespace and xns must be "http://www.mywebservice.com/schema/data" for it to work right.   You might only need one of those variables.