0

I have an xml that looks like this:

<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:

ItemHeadReturn
|-comment
|-searchComplete
|-resultList
|-resultList
|-resultList
|-search
|-search
|-search

The question is: How do I build the Class 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?

4

1 回答 1

1

您可以使用 XSD.exe 实用程序生成与您的 XML 对应的 C# 类:http: //msdn.microsoft.com/en-us/library/x6c1kb0s%28v=vs.110%29.aspx

打开 Visual Studio 命令提示符,导航到要存储生成的类的目录,然后键入:

xsd "MyFileFullPath.xml" 

这会从您的 XML 生成一个 XSD 文件。接着 :

xsd "MyGeneratedXSDFileFullPath.xsd" /c

生成 C# 类。

于 2013-10-14T08:10:09.833 回答