我正在尝试将具有基本类型和复杂对象的对象序列化为XML
格式,该格式使用XMLArrays
作为对象。我遇到困难,因为我需要按特定顺序订购每个XML元素,但是我收到以下错误消息:
"XmlElement, XmlText, and XmlAnyElement cannot be used in conjunction with XmlAttribute, XmlAnyAttribute, XmlArray, or XmlArrayItem."
这是我的代码:
public class XMLClaimFieldInfo
{
[XmlIgnore]
public int SectionID { get; set; }
[XmlElement(Order = 1)]
public string Name { get; set; }
[XmlElement(Order = 2)]
public string ClaimDataType { get; set; }
[XmlElement(Order = 3)]
public int UIGridRowLoc { get; set; }
[XmlElement(Order = 4)]
public int UIGridColLoc { get; set; }
[XmlElement(Order = 5)]
public int TabOrder { get; set; }
[XmlElement(Order = 6)]
public string DefaultValue { get; set; }
[XmlElement(Order = 7)]
public int? UIGridRowSpan { get; set; }
[XmlElement(Order = 8)]
public int? UIGridColSpan { get; set; }
[XmlElement(Order = 9)]
public string Format { get; set; }
[XmlElement(Order = 10)]
public bool IsHidden { get; set; }
[XmlElement(Order = 11)]
[XmlArrayItem("XMLClaimFieldSelectOption")]
public List<XMLClaimFieldSelectOption> ClaimFieldSelectOptions;
[XmlElement(Order = 12)]
[XmlArrayItem("XMLFieldValidation")]
public List<XMLFieldValidation> FieldValidations { get; set; }
[XmlElement(Order = 13)]
[XmlArrayItem("XMLClaimFieldObjectMap")]
public List<XMLClaimFieldObjectMap> ClaimFieldObjectMaps = new List<XMLClaimFieldObjectMap>();
我猜这是因为我使用XMLElement
属性的XMLArrayItem
属性?反正有吗?
答案 0 :(得分:4)
尝试使用[XmlArray(Order=13)]
代替[XmlElement(Order = 13)]
。