Category Archives: LINQ

Reading XML with Namespaces using LINQ

Introduction

On a recent .NET project I had to hook up with a web service that used non-standard headers in the request. After struggling with the configuration settings and the sparse Windows Communication Foundation (WCF) documentation for creating custom headers, I finally decided to skip WCF altogether and create the request as straight XML and manually process the XML in the response. It turned out to be easy (and straightforward), but I had a little trouble processing the returned XML using LINQ. The problem? The return XML had namespaces, which is common enough in the real world, but the .NET documentation and various blog posts showing how to process XML with LINQ don’t give much attention to namespaces. Continue reading