繁体   English   中英

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

[英]Xml Deserialization - Element with attributes and a value

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

<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元素不是。 我在这里说得对吗?

谢谢

尝试使用像这样的XmlText属性

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM