I am writing a WCF service that is supposed to return a following structure:
<trips>
<trip attribute1="" attribute2="">
<stops>
<stop attribute1="" attribute2="">
<element1/>
<element2>
</stop>
</stops>
</trip>
The class looks like following:
[XmlTypeAttribute(AnonymousType = true)]
[DataContract(Name = "Trip")]
public class tripStructure
{
/// <remarks/>
[DataMember(Order = 0)]
public string Number { get; set; }
/// <remarks/>
//[XmlAttribute]
[DataMember(Order = 1)]
public string Destination { get; set; }
/// <remarks/>
//[XmlAttribute]
[DataMember(Order = 2)]
public double Longitude { get; set; }
/// <remarks/>
//[XmlAttribute]
[DataMember(Order = 3)]
public double Latitude { get; set; }
/// <remarks/>
//[XmlAttribute]
[DataMember(Order = 4)]
public tripStructureStatus Status { get; set; }
/// <remarks/>
//[XmlAttribute]
[DataMember(Name = "UpdateTime", Order = 5)]
public DateTime TimeStamp { get; set; }
/// <remarks/>
[XmlArrayItem("Stop", IsNullable = false)]
[DataMember(Order = 6)]
public List<tripStructureStop> Stops { get; set; }
}
Class tripStructureStop is serializeble as well.
If XmlAttribute is commented out the result is following:
<Trips>
<Trip>
<Number>E432</Number>
<Destination>UN</Destination>
<Longitude>-79.4992</Longitude>
<Latitude>43.6153</Latitude>
<Status>S</Status>
<UpdateTime>2014-10-06T15:49:15.88</UpdateTime>
<Stops>
<Stop>
<ArrivalTime Scheduled="4:23:00 PM" Computed="4:16:52 PM" Status="E"/>
<DepartureTime Scheduled="4:30:00 PM" Computed="4:23:52 PM" Status="E"/>
<Code>UN</Code>
</Stop>
</Stops>
</Trip>
</Trip>
All properties are serialized as XmlElement. However, if I want to make them serialized as attributes and I uncomment [XmlAttribute] attribute, than, the entire property will disappear from XML
Any suggestions?