简体   繁体   中英

Xml Deserialization - Element with attributes and a value

I'm not quite sure how to deserialize the following:

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

In my C# model, I have a Property object, which contains a Price property, declared as follows:

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

Then in the Price class, I have the following:

   [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; }

        ....
    }

All the attributes are deserializing correctly, but the price element is not. Have I declared it correctly here?

Thanks

Try to use XmlText Attribute like this

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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