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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top