what is Difference between using XMLRoot/XMLElement and using Serializable() attributes?
how do i know when to use each ?
what is Difference between using XMLRoot/XMLElement and using Serializable() attributes? how do i know
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Here is a less than in depth description, but I think a good starting point.
XmlRootAttribute– Is used to provide schema information for the class that is going to be the root element of the object graph being serialized. This can only be applied to classes, structs, enums, interfaces of return values.XmlElementAttribute– Provides schema information for properties of a class controlling how they are serialized as child elements. This attribute can only be applied to fields (class variable members), properties, parameters and return values.The first two
XmlRootAttributeandXmlElementAttributerelate to the XmlSerializer.While the next, is used by the runtime formatters and does not apply when using XmlSerialization.
SerializableAtttrible– Is used to indicate that the type can be serialized by the runtime formatters like SoapFormatter or BinaryFormatter. This is only required if you need to serialize the type using one of the formatters and can be applied to delegates, enums, structs and classes.Here is a quick example that might help clarify the above.
Given the above, an instance of AddressBook serialized with an XmlSerializer would give XML of the following format