2011-07-14 32 views
0

我有一個使用XSD工具從xsd文件生成的類文件。我收到來自Web服務的XML字符串響應。如何使用接收到的字符串xml填充生成的類?從Web服務接收字符串並填充類

+0

您試圖在哪種編程語言中填充類? – Brabster

+0

Visual Studio C#2010 – user31673

+0

您所描述的填充類的過程通常稱爲解組。我不熟悉C#,但谷歌可能可以幫助你放棄這個詞。 – Brabster

回答

0

您可以使用System.Runtime.Serialization.DataContractSerializer來生成類。

TheClass result = null; 
DataContractSerializer dcs = new DataContractSerializer(typeof(TheClass)); 
using(StringReader reader = new StringReader(xml)) 
{ 
    using(XmlReader XmlReader = new XmlReader(reader)) 
    { 
     result = dcs.ReadObject() as TheClass; 
    } 
}