I have this class
public class Audit
{
public string name { get; set;}
public DateTime AuditDate { get; set;}
public long? DepartmentId {get; set;}
public string Department { get; set;}
public long? StateId { get; set;}
public string? State { get; set; }
public long? CountryId { get; set; }
public string Country { get; set; }
}
When I serialize it looks like this
<Audit>
<name>George</name>
<AuditDate>01/23/2013</AuditDate>
<DepartmentId>10</DepartmentId>
<Department>Lost and Found</Department>
<StateId>15</StateId>
<State>New Mexico</StateId>
<CountryId>34</CountryId>
<Country>USA</Country>
</Audit>
I added this class to try get the id fields as attribute
public class ValueWithId
{
[XmlAttribute ("id")]
public long? Id { get; set; }
[XmlText] // Also tried with [XmlElement]
public string Description { get; set; }
}
Rewrote my class to this
[Serializable]
public class Audit
{
public string name { get; set;}
public DateTime AuditDate { get; set;}
public ValueWithId Department { get; set;}
public ValueWithId State { get; set; }
public ValueWithId Country { get; set; }
}
But I get the error 'There was an error reflecting type Audit'
I am trying to get the following as the XML
<Audit>
<name>George</name>
<AuditDate>01/23/2013</AuditDate>
<Department id=10>Lost and Found</Department>
<State id=15>New Mexico</State>
<Country id=34>USA</Country>
</Audit>
Thanks