I am trying to serialize an XML into a Class, PostalAddress. The Postal Address looks like this
public class PostalAddress
{
public string DeliverTo { get; set; }
public string Street { get; set; }
public string City { get; set; }
public string PostalCode { get; set; }
[XmlAttribute("isoCountryCode")]
public string CountryCode { get; set; }
public string Country { get; set; }
}
The input XML document is
<PostalAddress>
<DeliverTo>SomeBody</DeliverTo>
<Street>Some Street Address</Street>
<City>MyCity</City>
<PostalCode>US-1013</PostalCode>
<Country isoCountryCode="US">US</Country>
</PostalAddress>
The C# code I am using for Serializing is
Now After Deserialization, I am able to see the values from XML in the corresponding properties but It is Missing the Attribute Value which I wanted to map into a Property, CountryCode.
var serializer = new XmlSerializer(typeof(PostalAddress));
var xmlReaderSettings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Parse}
PostalAddress postalAddress;
using (var reader = XmlReader.Create(new StringReader(inputDocument.ToString()), xmlReaderSettings))
{
postalAddress= (PostalAddress)serializer.Deserialize(reader);
}
Can you please help where am I missing things here?``