Is there a way to retrieve elements using only local names in a Linq-to-XML query?

linq-to-xml

Solution

var q = from x in doc.Root.Elements()
        where x.Name.LocalName=="RegistryErrorList"
        select x;

var errorList = q.SingleOrDefault();

Problem

Lets assume we have this xml: ``` <?xml version="1.0" encoding="UTF-8"?> <tns:RegistryResponse status="urn:oasis:names:tc:ebxml-regrep:ResponseStatusType:Failure" xmlns:tns="urn:oasis:names:tc:ebxml-regrep:xsd:rs:3.0" xmlns:rim="urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0"> <tns:RegistryErrorList highestSeverity=""> <tns:RegistryError codeContext="XDSInvalidRequest - DcoumentId is not unique." errorCode="XDSInvalidRequest" severity="urn:oasis:names:tc:ebxml-regrep:ErrorSeverityType:Error"/> </tns:RegistryErrorList> </tns:RegistryResponse> ``` To retrieve RegistryErrorList element, we can do ``` XDocument doc = XDocument.Load(<path to xml file>); XNamespace ns = "urn:oasis:names:tc:ebxml-regrep:xsd:rs:3.0"; XElement errorList = doc.Root.Elements( ns + "RegistryErrorList").SingleOrDefault(); ``` but not like this ``` XElement errorList = doc.Root.Elements("RegistryErrorList").SingleOrDefault(); ``` Is there a way to do the query without the namespace of the element. Basicly is there something conceptially similiar to using local-name() in XPath (i.e. //*[local-name()='RegistryErrorList'])

Original source