Xml反序列化 - 具有属性和值的元素

时间:2014-01-06 23:56:31

标签: c# xml xml-serialization

我不太确定如何反序列化以下内容:

<property>
    <price display="yes" plusSAV="no" tax="yes">1000000</price>
    ...
</property>

在我的C#模型中,我有一个Property对象,它包含一个Price属性,声明如下:

    [XmlElement("price")]
    public Price Price { get; set; }

然后在Price课程中,我有以下内容:

   [Serializable]
    public class Price : BaseDisplayAttribute, IDataModel
    {        
        [XmlElement("price")]
        public string PriceValueString { get; set; }

        [XmlAttribute("plusSAV")]
        public string PlusSAVString { get; set; }

        [XmlAttribute("tax")]
        public string TaxString { get; set; }

        ....
    }

所有属性都正确反序列化,但price元素不是。我在这里说得对吗?

由于

1 个答案:

答案 0 :(得分:2)

尝试使用XmlText Attribute这样的

[XmlText]
public string PriceValueString { get; set; }