I have to serialize my objects to a XML document in a certain order.
<?xml version="1.0"?>
<__Root __version="1.1" __encryption="2">
<__service __serviceType="Test">
<__inputData>
<BaseToChange>
<__name>TestName</__name>
</BaseToChange>
</__inputData>
<__perform>
<__eventName>Event</__eventName>
</__perform>
<__inputData>
<ObjectChanges>
<Name>Test</Name>
</ObjectChanges>
</__inputData>
<__execute />
<__requestData>
<CompletionMsg />
</__requestData>
</__service>
</__Root>
The problem I have now is that I'm not able to serialize my List<InputData>
with the Element Perform
in between.
public class Service
{
[XmlAttribute("__serviceType")]
public string ServiceType { get; set; }
[XmlElement("__perform")]
public Perform Perform { get; set; }
[XmlElement("__inputData")]
public List<InputData> InputData{ get; set; }
[XmlElement("__execute")]
public Execute Execute { get; set; }
[XmlElement("__requestData")]
public RequestData RequestData{ get; set; }
public Service() { }
}
The order has to be as shown. So first <__inputData>
, then <__perform>
, followed by any remaining <__inputData>
.
I already tried to separate the Properties and therefore the XmlElements but as soon I want to serialize with two elements having the same name I get an error.
Does anyone have an idea how to accomplish that?