How do I add an XML attribute using DataContract?

You can't add attributes to a DataContract. You either have to use a class that Implements ISerializable or use the . Net XmlSerializer.

IXmlSerializable for xml. – user295190 Jan 19 at 22:51 Depending on the system doing the serialization, it is possible to do what the OP is asking - see: stackoverflow. Com/questions/4858798/… – jeffreypriebe Oct 23 at 1:32.

I was also looking for a solution for something like this, I found it here on stackoverflow, at DataContract XML serialization and XML attributes.

Not exactly an answer, but you can try to implement IXmlSerializable to fully control output xml format.

I think this could do the trick : DataContract(Name = "Test", Namespace = "") public class Test { DataMember(Order = 0, Name = "Text") public string Text { get; set; } XmlAttribute("type") public Type Type { get { return this.GetType(); } } public Test() { } } Hope this helps, Regards. EDIT: Forget this, things mixed up in my head and every synapses connections gone wrong there... (and anyway, I mixed DataContract and XML serialization attributes, and worst I was putting the attribute in the "Test" element instead of "Text" element). As other people said, with DataContract you will have to make your own serialization implementation with ISerializable.

– alexdej Nov 7 '09 at 5:05 Of course, this case shows up how it could be helpful. – Ucodia Nov 7 '09 at 15:24.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions