Convert an object to an XML string

thp192a

New Member
I have got a class named \[code\]WebserviceType\[/code\] I got from the tool xsd.exe from an XSD file. Now I want to deserialize an instance of an \[code\]WebServiceType\[/code\] object to a string. How can I do this?The \[code\]MethodCheckType\[/code\] object has as params a \[code\]WebServiceType\[/code\] array.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\]).This is the method in which I serialize the \[code\]WebServiceType\[/code\] object:\[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\]Edit: 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.
 
Back
Top