title: Convert byte[] array to XDocument
body: <p>I am trying to convert byte[] array into XDocument in WP. I have following code </p>
  
  <pre><code> private void btnDownload_Click(object sender, RoutedEventArgs e)
      {
          svc.DownloadFileCompleted += new EventHandler&lt;DownloadFileCompletedEventArgs&gt;(svc_DownloadFileCompleted);
          svc.DownloadFileAsync("XMLFile1.xml");
      }
  
      void svc_DownloadFileCompleted(object sender, DownloadFileCompletedEventArgs e)
      {
          byte[] bytes = e.Result;
          //string responseText = Encoding.UTF8.GetString(bytes,0,2048);  //  ASCII assumed
          //XDocument respnseXml = XDocument.Load(responseText);
          bytes = NullRemover(bytes);
          using (MemoryStream stream = new MemoryStream(bytes))
          {
              XDocument document = XDocument.Load(stream);
          }
      }
      private byte[] NullRemover(byte[] DataStream)
      {
          int i;
          byte[] temp = new byte[DataStream.Length];
          for (i = 0; i &lt; DataStream.Length - 1; i++)
          {
              if (DataStream[i] == 0x00) break;
              temp[i] = DataStream[i];
          }
          byte[] NullLessDataStream = new byte[i];
          for (i = 0; i &lt; NullLessDataStream.Length; i++)
          {
              NullLessDataStream[i] = temp[i];
          }
          return NullLessDataStream;
      }
  </code></pre>
  
  <p>I have created a web service which download the file. My code works fine. It converts byte[] into XDocument object. I am not sure this way is correct or not. Why there is need to use <strong>MemoryStream</strong>? Is it correct way to convert <strong>byte[]</strong> into <strong>XDocument</strong>?  Or there is any another way to convert? </p>