0
我有困難序列化提交的數據屬性爲以下,特別是提交的數據元素這是一個數組和每個submittedData元素都有一個字段數組(在此示例中每個提交的數據只顯示1 )。 xsd.exe轉換器也不處理submittedData部分。c#XML序列化到對象與多個陣列
任何建議將不勝感激。
<?xml version="1.0" encoding="UTF-8"?>
<forms>
<site>https://www.sample.com</site>
<export_date>2017-08-09T12:04:11-04:00</export_date>
<webform name="form A">
<crmFormId>form_A</crmFormId>
<version>1.0</version>
<formData>
<WEBFORMNODESTATUS>Unpublished</WEBFORMNODESTATUS>
<submittedData>
<field>
<crmFieldKey>aEXTERNALID</crmFieldKey>
<crmFieldValue>1000</crmFieldValue>
</field>
</submittedData>
<submittedData>
<field>
<crmFieldKey>bEXTERNALID</crmFieldKey>
<crmFieldValue>2000</crmFieldValue>
</field>
</submittedData>
</formData>
</webform>
<webform name="form_B">
<crmFormId>2</crmFormId>
<version>1.0</version>
<formData>
<WEBFORMNODESTATUS>Unpublished</WEBFORMNODESTATUS>
<submittedData>
<field>
<crmFieldKey>cEXTERNALID</crmFieldKey>
<crmFieldValue>1001</crmFieldValue>
</field>
</submittedData>
<submittedData>
<field>
<crmFieldKey>dEXTERNALID</crmFieldKey>
<crmFieldValue>1002</crmFieldValue>
</field>
</submittedData>
</formData>
</webform>
</forms>
這是我正在使用的類。一切都很好,直到我嘗試使用submittedData元素。
[XmlRoot()]
public class forms
{
private string siteField;
private string export_dateField;
private formsWebform[] webformField;
[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string site
{
get
{
return this.siteField;
}
set
{
this.siteField = value;
}
}
[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string export_date
{
get
{
return this.export_dateField;
}
set
{
this.export_dateField = value;
}
}
[System.Xml.Serialization.XmlElementAttribute("webform", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public formsWebform[] webform
{
get
{
return this.webformField;
}
set
{
this.webformField = value;
}
}
}
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public partial class formsWebform
{
private string crmFormIdField;
private string versionField;
private formsWebformFormData formDataField;
private string nameField;
[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string crmFormId
{
get
{
return this.crmFormIdField;
}
set
{
this.crmFormIdField = value;
}
}
[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string version
{
get
{
return this.versionField;
}
set
{
this.versionField = value;
}
}
[System.Xml.Serialization.XmlElementAttribute("formData", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public formsWebformFormData formData
{
get
{
return this.formDataField;
}
set
{
this.formDataField = value;
}
}
[System.Xml.Serialization.XmlAttributeAttribute()]
public string name
{
get
{
return this.nameField;
}
set
{
this.nameField = value;
}
}
}
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public partial class formsWebformFormData
{
private string wEBFORMNODESTATUSField;
[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string WEBFORMNODESTATUS
{
get
{
return this.wEBFORMNODESTATUSField;
}
set
{
this.wEBFORMNODESTATUSField = value;
}
}
private List<SubmittedDataFields> submittedDataField;
[System.Xml.Serialization.XmlArray("submittedData")]
[System.Xml.Serialization.XmlArrayItem("field")]
public List<SubmittedDataFields> submittedData
{
get
{
return this.submittedDataField;
}
set
{
this.submittedDataField = value;
}
}
}
public partial class SubmittedDataFields
{
private formsWebformFormDataSubmittedDataField[] data;
public formsWebformFormDataSubmittedDataField[] fields
{
get{
return this.data;
}
set {
this.data = value;
}
}
}
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public partial class formsWebformFormDataSubmittedDataField
{
private string crmFieldKeyField;
private string crmFieldValueField;
[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string crmFieldKey
{
get
{
return this.crmFieldKeyField;
}
set
{
this.crmFieldKeyField = value;
}
}
[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string crmFieldValue
{
get
{
return this.crmFieldValueField;
}
set
{
this.crmFieldValueField = value;
}
}
}
感謝您的答覆。但是,submittedData也是一個數組或列表。這個想法是每個表單有多個表單完成多個領域。 我所做的修復到.. [XmlElement的( 「submittedData」)] 公共字符串crmFieldKey –
我製成的修復可.. [XmlElement的( 「submittedData」)] 公共字符串crmFieldKey 至[XmlElement的( 「crmFieldKey」 )] 公共字符串crmFieldKey –
進行少量編輯 - 可能正在工作。 –