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’])
1 Answer