Pregunta

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?

¿Fue útil?

Solución

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

Open a Visual Studio Command Prompt, navigate to the directory you want to store the generated class, and then type :

xsd "MyFileFullPath.xml" 

This generate a XSD file from you XML. And then :

xsd "MyGeneratedXSDFileFullPath.xsd" /c

To generate the C# class.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top