[英]how to serialize complex object with arrays
I have an xml that looks like this:我有一个如下所示的 xml:
<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>
...
Basically, the structure of SOAPRequestItemHeadReturn is the following:基本上,SOAPRequestItemHeadReturn 的结构如下:
ItemHeadReturn
|-comment
|-searchComplete
|-resultList
|-resultList
|-resultList
|-search
|-search
|-search
The question is: How do I build the Class SOAPRequestItemHeadReturn
?问题是:如何构建
SOAPRequestItemHeadReturn
类? Here is a possible structure:这是一个可能的结构:
public class SOAPItemRevisionHeadResult{
public string comment { get; set;}
public bool searchComplete { get; set;}
public SearchType[] search { get; set;}
public StringMap[] resultList {get; set;}
}
And I need to fill in the attributes, but I don't know which attributes and where.而且我需要填写属性,但我不知道哪些属性和在哪里。 Any Ideas?
有什么想法吗?
You can use the XSD.exe utility to generate your C# class corresponding to your XML : http://msdn.microsoft.com/en-us/library/x6c1kb0s%28v=vs.110%29.aspx您可以使用 XSD.exe 实用程序生成与您的 XML 相对应的 C# 类: http : //msdn.microsoft.com/en-us/library/x6c1kb0s%28v=vs.110%29.aspx
Open a Visual Studio Command Prompt, navigate to the directory you want to store the generated class, and then type :打开 Visual Studio 命令提示符,导航到要存储生成的类的目录,然后键入:
xsd "MyFileFullPath.xml"
This generate a XSD file from you XML.这将从您的 XML 生成一个 XSD 文件。 And then :
然后:
xsd "MyGeneratedXSDFileFullPath.xsd" /c
To generate the C# class.生成 C# 类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.