How to query an XDocument with LINQ when elements have a colon in their name?

Viewed 11820

I am trying to use LINQ to XML in an with the XDocument object. How do you query the result element in the example below?

<serv:header>
   <serv:response>
      <serv:result>SUCCESS</serv:result>
      <serv:gsbStatus>PRIMARY</serv:gsbStatus>
   </serv:response>
</serv:header>

When I use a statement like this, I get the exception 'Additional information: The ':' character, hexadecimal value 0x3A, cannot be included in a name.'

XDocument doc = XDocument.Parse(xml);
string value = doc.Descendants("serv:header").First().Descendants("serv:response").First().Descendants("serv:result").First().Value;
2 Answers
Related