Is it possible to serialize a C# object to an XML file with this special format?
class Job
{
Guid JobGuid;
List<Source> Sources;
}
I want to get this XML format:
Module_n (with n the index of the sub-element) instead of Source
<job JobGuid=".....">
<Sources>
<Module_1> </Module_1>
<Module_2> </Module_2>
</Sources>
</job>
jobGuidjust add[XmlAttribute("JobGuid")]to theJobGuidproperty. But getting the required list element names means you will have to implementIXmlSerializable, which is quite burdensome. To get started see How do you deserialize XML with dynamic element names? and how to derive xml element name from an attribute value of a class using annotations?. But this XML is poorly designed since it cannot have a proper XSD. Do you have freedom to change the format?Joband the propertiesJobGuidandSourcespublic.