Is there any way to get the xml serializer to convert the following:
class Mail
{
public string Subject = "sub1";
}
into the following XML schema:
<Mail>
<MailSubject>
<Subject>sub1</Subject>
</MailSubject>
</Mail>
That is I want to wrap the xmlElement in a new xmlElement group without using the following sub class:
class Mail
{
public MailSubject MailSubject = new MailSubject();
}
class MailSubject
{
public string Subject = "sub1";
}
My xml format comes from a 3rd party and I’m trying to make it so that our objects make sense and are easily usable while still keeping to their xml schema.
As Buh Buh said, the only way to do this by implementing IXmlSerializable. A possible implementation would look like this: