title: Convert an object to an XML string
body: <p>I have got a class named <code>WebserviceType</code> I got from the tool xsd.exe from an XSD file.  </p>
  
  <p>Now I want to deserialize an instance of an <code>WebServiceType</code> object to a string. 
  How can I do this?</p>
  
  <p>The <code>MethodCheckType</code> object has as params a <code>WebServiceType</code> array.</p>
  
  <p>My first try was like I serialized it: with a <code>XmlSerializer</code> and a <code>StringWriter</code> (while serializing I used a <code>StringReader</code>).</p>
  
  <p>This is the method in which I serialize the <code>WebServiceType</code> object:</p>
  
  <pre><code>XmlSerializer serializer = new XmlSerializer(typeof(MethodCheckType));
          MethodCheckType output = null;
          StringReader reader = null;
  
          // catch global exception, logg it and throw it
          try
          {
              reader = new StringReader(path);
              output = (MethodCheckType)serializer.Deserialize(reader);
          }
          catch (Exception)
          {
              throw;
          }
          finally
          {
              reader.Dispose();
          }
  
          return output.WebService;
  </code></pre>
  
  <hr>
  
  <p>Edit:   </p>
  
  <p>Maybe I could say it in different words: I have got an instance of this <code>MethodCheckType</code> object an on the other hand I have got the XML document from which I serialized this object. Now I want to convert this instance into a XML document in form of a string. After this I have to proof if both strings (of XML documents) are the same. This I have to do, because I make unit tests of the first method in which I read an XML document into a <code>StringReader</code> and serialize it into a <code>MethodCheckType</code> object.</p>