title: Why does my web service response XML contain escape characters and how should they be handled?
body: <p>Here's the relevant (C#.NET) code:</p>
  
  <pre><code>WebRequest webRequest = System.Net.WebRequest.Create(authenticationUrl);
  
  UTF8Encoding encoding = new UTF8Encoding();
  
  ...
  
  var webResponse = webRequest.GetResponse();
  var webResponseLength = webResponse.ContentLength;
  byte[] responseBytes = new byte[webResponseLength];
  
  webResponse.GetResponseStream().Read(responseBytes, 0, (int)webResponseLength);
  var responseText = encoding.GetString(responseBytes);
  webResponse.Close();
  </code></pre>
  
  <p>Here's what the value of <code>responseText</code> looks like (as copied from Visual Studio while debugging the above code):</p>
  
  <pre><code>"&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n&lt;responseblock version=\"3.67\"&gt;\n  &lt;requestreference&gt;X3909254&lt;/requestreference&gt;\n  &lt;response type=\"ERROR\"&gt;\n    &lt;timestamp&gt;2012-04-16 13:53:59&lt;/timestamp&gt;\n    &lt;error&gt;\n      &lt;message&gt;Invalid field&lt;/message&gt;\n      &lt;code&gt;30000&lt;/code&gt;\n      &lt;data&gt;baseamount&lt;/data&gt;\n    &lt;/error&gt;\n  &lt;/response&gt;\n&lt;/responseblock&gt;\n"
  </code></pre>
  
  <p>Why are there seemingly escape characters (e.g. <code>\"</code>) in the response? Is this due to the way in which I'm converting the response stream to a string? What should I do instead (so that the value stored in the variable <code>responseText</code> can be parsed as 'standard' XML)?</p>
  
  <p>UPDATE – some more code that I was using:</p>
  
  <pre><code>var resultXML = XElement.Parse(responseText);
  
  ...
  
  
  int errorCode = (int)(resultXML.Element("error").Element("code"));
  </code></pre>
  
  <p>The problem was that the element <code>error</code> isn't a direct child of the root element of <code>resultXML</code>, hence my apparent inability to reference <code>error</code> (or its child element <code>code</code>).</p>