Customizing XML Serialization

  • Thread starter Thread starter Raj
  • Start date Start date
R

Raj

How do I custom serialize a class like this way.

<rootelement attribute1="val1" attribute2="val2">
<childlement childattribute1="val1" childattribute2="val2"/>
<childlement childattribute1="val1" childattribute2="val2"/>
</rootelement>

Thank you

Regards
Raj
 
Raj said:
How do I custom serialize a class like this way.

<rootelement attribute1="val1" attribute2="val2">
<childlement childattribute1="val1" childattribute2="val2"/>
<childlement childattribute1="val1" childattribute2="val2"/>
</rootelement>

Thank you

Regards
Raj

I would first see how serialization would output without any specific
mapping, i.e. mark the classes as serializable, create an XmlSerializer,
and look at the output. I think properties will get serialized as
elements, but you'll have to check.

If the output doesn't meet your requirements, you can map the classes
explicitly using the XmlTypeAttribute, XmlElementAttribute and
XmlAttributeAttribute classes (amongst others, if necessary).

see http://msdn.microsoft.com/en-us/library/83y7df3e.aspx for an
overview of attributes that control xml serialization and more information.
 
Back
Top