A snippet of the XML im querying is
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <metadata created="2014-11-03T18:13:02.769Z" xmlns="http://example.com/ns/mmd-2.0#" xmlns:ext="http://example.com/ns/ext#-2.0"> <customer-list count="112" offset="0"> <customer id="5f6ab597-f57a-40da-be9e-adad48708203" type="Person" ext:score="100"> <name>Bobby Smith</name> <gender>male</gender> <country>US</country> <birth-span> <start>1965-02-18</start> <end>false</end> </birth-span> The code im writing to get the elements is
GetCustomer = from c in XDoc.Descendants(ns + "customer") select new Customer { Name = c.Element(ns + "name").ToString(), Gender = Convert.ToString(c.Element(ns + "gender")), BeginDate = c.Elements("birth-span").Any() ? c.Element("start").Value.ToString() : "No data found" The problem i have is with birth-span, i never seem to get the value if birth-span exists (there are some records which do not contain the birth-span element). For the records that do contain the birth-span element i have added the namespace variable which doesnt work (throws the error that object is not set to an instance)
BeginDate = c.Elements(ns + "birth-span").Any() ? c.Element(ns + "start").Value.ToString() : "No data found" Ive added different variations but either i get the value No Data found OR an error (Seems to be object not set to an instance). Can anyone see what im doing wrong?