title: Creating an Xdocument object from XmlNode
body: <p>I have a call to a SOAP/XML type web service that is successfully returning an XML response. </p>
  
  <p>So far, I have managed to take the returned object, cast it to an XmlNode object.. and have found the actual data in there as expected. All good.</p>
  
  <p>Now, though, I want to bind my data to a DataGridView in a Windows Form.
  I saw a nice example here <a href="https://stackoverflow.com/questions/1327016/c-sharp-datagridview-binding-to-subset-of-xml">C# DataGridView binding to subset of XML</a> using an XDocument and LINQ to provide a DataSource for the grid that would seem to work really well for me.</p>
  
  <p>The problem I have is that I don't know how to create an XDocument based on the object returned by my call to the web service. How can I do this ?</p>
  
  <p>This is how I have captured the returned data from the webservice.. which works..  </p>
  
  <pre><code>' call the webservice  '
  Dim rawResults As Object = lw.runQuery(parameter1,parameter2)
  
  Dim testresult As XmlNode = DirectCast(rawResults, XmlNode)
  
  Dim docXml As New XmlDocument
  docXml.AppendChild(docXml.ImportNode(testresult, True)).
  
  .etc
  </code></pre>
  
  <p>Here is the XML returned by the webservice.. (Each "runQueryResult" will become a row in the DataGridView)</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
    &lt;soap:Body&gt;
      &lt;runQueryResponse xmlns="http://xxx.ddd.com/"&gt;
      &lt;runQueryResult&gt;
          &lt;runQueryResponse xmlns=""&gt;
          &lt;runQueryRecord&gt;
              &lt;catalogid&gt;513&lt;/catalogid&gt;
              &lt;name&gt;Vacuum tube &lt;/name&gt;
              &lt;this_month&gt;0&lt;/this_month&gt;
              &lt;month_past1&gt;1&lt;/month_past1&gt;
              &lt;month_past2&gt;0&lt;/month_past2&gt;
              &lt;month_past3&gt;0&lt;/month_past3&gt;
              &lt;month_past4&gt;0&lt;/month_past4&gt;
              &lt;month_past5&gt;0&lt;/month_past5&gt;
              &lt;month_past6&gt;0&lt;/month_past6&gt;
          &lt;/runQueryRecord&gt;
          &lt;runQueryRecord&gt;
              &lt;catalogid&gt;5311&lt;/catalogid&gt;
              &lt;name&gt;Adapter expansion&lt;/name&gt;
              &lt;this_month&gt;0&lt;/this_month&gt;
              &lt;month_past1&gt;1&lt;/month_past1&gt;
              &lt;month_past2&gt;0&lt;/month_past2&gt;
              &lt;month_past3&gt;0&lt;/month_past3&gt;
              &lt;month_past4&gt;0&lt;/month_past4&gt;
              &lt;month_past5&gt;0&lt;/month_past5&gt;
              &lt;month_past6&gt;0&lt;/month_past6&gt;
  
                              ... etc.
  </code></pre>