Create the target model (POCO-ish) based on the target xsd using the MS xsd tool and perform the conversion in the code through which it hides the translation implementation.
To simplify the conversion, you can use, for example, Automapper on github .
From the target model it would be easy to create XML, JSON or save data using, for example, the Entity Framework.
An example of JSON gene serialization:
public static string GetString<T>(T value) { using (var ms = new MemoryStream()) { var ser = new DataContractJsonSerializer(typeof(T)); ser.WriteObject(ms, value); byte[] json = ms.ToArray(); ms.Close(); return Encoding.UTF8.GetString(json, 0, json.Length); } }
I have tried the XSLT route in the past, and although it is powerful, it tends to develop rapidly. With the target model above, you can debug your conversions, if necessary, and also offers you a number of opportunities to move forward.
Re: AutoMapper , in this case, when the target structure is complex and possibly different from the source, it is difficult to automatically display AutoMapper, I usually create Orchestrator / SuperMapper, which is responsible for the general structure / display, which uses AutoMapper internally.
Tip. If the target object requires values ββfrom several, you can set it as a sequence of mappings to the same object by looking at this question / answer .
It is difficult to give a good general answer without special structures in mind.
Re: Facade Wikipedia has a good definition of this template β Facade on Wikipedia But briefly define the simplest possible interface for your Orchestrator / SupperMapper so that you separate the internal work of translating the structure from the rest of your application. This way you can easily exchange it for something else when your needs change. Thus, the rest of the application does not need to know about AutoMapper or the target model. All he knows is to include the original model and expect, for example, to return Json.