C# 如何用数组序列化复杂对象
我有一个如下所示的xml:C# 如何用数组序列化复杂对象,c#,xml,xml-serialization,xml-deserialization,C#,Xml,Xml Serialization,Xml Deserialization,我有一个如下所示的xml: <SOAPRequestItemHeadReturn xmlns:ns2="fsw" xsi:type="ns2:SOAPItemRevisionHeadResult"> <comment xsi:type="xsd:string" xsi:nil="true"/> <searchComplete xsi:type="xsd:boolean&
<SOAPRequestItemHeadReturn xmlns:ns2="fsw" xsi:type="ns2:SOAPItemRevisionHeadResult">
<comment xsi:type="xsd:string" xsi:nil="true"/>
<searchComplete xsi:type="xsd:boolean">true</searchComplete>
<resultList xsi:type="ns2:SOAPItemRevisionHead">
<stringKey xsi:type="xsd:string">ItemRevision.ItemID</stringKey>
<stringValue xsi:type="xsd:string">cam_english_template</stringValue>
</resultList>
<resultList xsi:type="ns2:SOAPItemRevisionHead">
<stringKey xsi:type="xsd:string">ItemRevision.ItemID</stringKey>
<stringValue xsi:type="xsd:string">cam_english_template</stringValue>
</resultList>
<search xsi:type="ns2:SearchType">
<value xsi:type="xsd:string">ItemRevision.ItemID</stringKey>
<used xsi:type="xsd:boolean">true</searchComplete>
</search>
...
问题是:如何构建类SOAPRequestItemHeadleTurn
?以下是一种可能的结构:
public class SOAPItemRevisionHeadResult{
public string comment { get; set;}
public bool searchComplete { get; set;}
public SearchType[] search { get; set;}
public StringMap[] resultList {get; set;}
}
我需要填写属性,但我不知道哪些属性和位置。有什么想法吗?您可以使用XSD.exe实用程序生成与XML对应的C#类: 打开Visual Studio命令提示符,导航到要存储生成的类的目录,然后键入:
xsd "MyFileFullPath.xml"
这将从XML生成一个XSD文件。然后:
xsd "MyGeneratedXSDFileFullPath.xsd" /c
要生成C#类。必须对xml进行一点编辑,但它成功了,谢谢。我希望使用xmlArrayAttibute和XmlArrayElementAttribute,为什么xsd没有使用它们?它没有使用这些属性,因为它们不是强制性的。默认行为足以根据需要运行序列化。
xsd "MyGeneratedXSDFileFullPath.xsd" /c