Jeeby
Jeeby

Reputation: 1464

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

Upvotes: 0

Views: 138

Answers (1)

Selman Gen&#231;
Selman Gen&#231;

Reputation: 101731

Try to use XmlText Attribute like this

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

Upvotes: 2

Related Questions