title: Approach for transforming XML to new XML format; If using Objects, limits configuration abilities?
body: <p>Have a question regarding an approach to transforming XML from one format to another.</p>
  
  <p>I am working on a task in which I am taking serialized data from an object I do not have control over. I have generated an object for this XML. Lets called this the "Form Instance". Form Instance is very complicated with nesting, and lots of irrelevant layout components and nesting which my understanding makes it hard to use XSLT for this.</p>
  
  <p>I need to take the Form instance, and assign properties from it - to values in another object. Lets call the other object "Standard Format". The standard format object serializes itself to the format I need to ultimately get to.</p>
  
  <p>The Form Instance is the resulting serialization from a user filling out a Form. This Form "definition" can be changed anytime and something as simple as a layout change to the form completely changes the nesting structure of the resulting serialization - what is consistent is that somewhere in the serialization Controls are represented that I need values from - and I want to configure which ones I want the values from.</p>
  
  <p>I am creating my own XML "Configuration File", which will allow specification of which Controls from the Form Instance I want to ultimately have loaded into the "Standard Format" object.</p>
  
  <p>Form Instance is structured like this:</p>
  
  <pre><code>&lt;Form name="MainForm"&gt;
  &lt;Control type="GroupHeader"&gt;
  &lt;Control type="GroupHeader"&gt;
  &lt;Control type="text" name="FirstName"/&gt;
  &lt;Control type="text" name="LastName"/&gt;
  &lt;/Control&gt;
  &lt;Control type="Radio" name="Gender"/&gt;
  &lt;/Control&gt;
  &lt;Control&gt;
  &lt;Form name="SomeOtherSubForm"&gt;
  &lt;Control type="text" name="AnotherPersonFirstName"/&gt;
  &lt;Control type="text" name="AnotherPersonLastName"/&gt;
  &lt;/Form&gt;
  &lt;/Control&gt;
  &lt;/Form&gt;
  </code></pre>
  
  <p>As you can see I don't mind really where the fields exist in Form instance(and it can change anytime if someone removes a group header or adds some new layout) as I can get to them recursively if I create a configuration file with the Control "name".</p>
  
  <p>I would like to make my "Configuration File", re-usable enough in the sense that - when data is added to the "Form Instance" - an adjustment can be made to my configuration file, saying "I now want this other control which was added to the Form definition" which will write it to the "Standard Format". Also, the ultimate output I would like to be configurable from this file as well.</p>
  
  <p>Serialization in the "Standard Format" object gets me what I need - if I work with it in a way specific to what I'm trying to end up with (it is flexible). However I am wondering, how I can make how the placement of my Form Instance data into that object - configurable. If I work with it as an object, then when the resulting serialization format needs to change I need to change code.</p>
  
  <p>Am I wrong in thinking, that since I know what the "Standard Format" object outputs, that I can create a token-like configuration section in my "Configuration File" to allow for the specification of the format?</p>
  
  <p>For example: 
  On my "Form Instance" I have at least 2 fields that I want to eventually have represented in what "Standard Format" serializes to. These 2 fields can change position/nesting in the "Form Instance" serialization anytime if someone changes the definition of the underlying Form that is defined.</p>
  
  <p>Since our objective is not to work with the Standard Format object, but end up with what it serializes, can I cut the object step out and just model towards the XML I want. For example this is what the Standard Format would produce if I added a "Person" object to it.</p>
  
  <pre><code>&lt;StandardFormat&gt;
    &lt;Person Gender="M"&gt;
      &lt;Name&gt;
        &lt;First&gt;Joe&lt;/First&gt;
        &lt;Last&gt;Smith&lt;/Last&gt;
      &lt;/Name&gt;
    &lt;/Person&gt;
  &lt;/StandardFormat&gt;
  </code></pre>
  
  <p>Would it be OK approach to make my XML Configuration file like this:</p>
  
  <pre><code>&lt;FormInstanceOutputConfiguration&gt; 
    &lt;Control id="FirstName" type="TextField"&gt;
    &lt;Control id="LastName" type="TextField"&gt;
    &lt;Control id="Gender" type="Radio"&gt;
    &lt;CustomOutputTemplate&gt;
      &lt;Person Gender="[Gender]"&gt;
        &lt;Name&gt;
          &lt;First&gt;[FirstName]&lt;/First&gt;
          &lt;Last&gt;[LastName]&lt;/Last&gt;
        &lt;/Name&gt;
      &lt;/Person&gt;
    &lt;/CustomOutputTemplate&gt;
  &lt;/FormInstanceOutputConfiguration&gt;
  </code></pre>
  
  <p>The desired output can change without the "Standard Format" model needing to change. If Person in this case was thought of as an actor, it can go under "" in the standard format object, or it could be nested under something else like "". I have multiple forms, but all of the "Controls" in each form will have same output. So in this case the main Form will have a bunch of different Persons all needing to come out in the same format.</p>
  
  <p>So is it bad if I go around the Standard Format object, if ultimately all we need is a serialization output?</p>
  
  <p>Thank you for any ideas.</p>