0

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>
3
  • But not easy. For jobGuid just add [XmlAttribute("JobGuid")] to the JobGuid property. But getting the required list element names means you will have to implement IXmlSerializable, 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? Commented Mar 18, 2017 at 16:49
  • Also, make the class Job and the properties JobGuid and Sources public. Commented Mar 18, 2017 at 16:50
  • Unfortunately, i have to respect this format. I would like to build a API that do the same thing as the original API. Commented Mar 20, 2017 at 8:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.