Convert custom string to xml
<p>Custom string format to xml help needed. Java and C#.</p>

<p><code>[Node(X)][CHILD0(Y)][OBJECT1(A)][Key1(1)][Key2(2)]</code><br>
<code>[Node(X)][CHILD0(Y)][OBJECT1(B)][Key1(1)][Key2(2)][Key3(3)]</code><br>
<code>[Node(X)][CHILD0(Y)][OBJECT1(C)][Key1(4)]</code><br>
<code>[Node(X)][CHILD0(Y)][OBJECT2(A)][Key1(1)][Key2(2)][Key3(3)]</code><br>
<code>[Node(X)][CHILD0(Y)][OBJECT2(B)][Key1(4)][Key2(5)]</code><br>
<code>[Node(X)][CHILD1(Z)][OBJECT1(A)][Key1(7)][Key2(8)][Key3(9)]</code><br>
<code>[Node(X)][CHILD1(Z)][OBJECT2(A)][Key1(15)][Key2(18)]</code>  </p>

<p>There may be 'n' number of string rows like the above samples.
What is the best method to serialize this to an xml file as below</p>

<p>If the below shown xml is also incorrect, then please advise the correct format as well. 
I tried serializing using some examples provided in stackoverflow and code project, but I'm unable 
to get the xml in the below format. Trying to do it in java and c#. Thank you all in advance. </p>

<pre><code>[X]
    [Y]  
        [OBJECT1]
            [A]
                &lt;Key1&gt;1&lt;/Key1&gt;
                &lt;Key2&gt;2&lt;/Key2&gt;
            [/A]
            [B]
            &lt;Key1&gt;2&lt;/Key1&gt;
            &lt;Key2&gt;2&lt;/Key2&gt;
            &lt;Key3&gt;3&lt;/Key3&gt;
        [/B]
        [C]
            &lt;Key1&gt;4&lt;/Key1&gt;
        [/C]
    [/OBJECT1]
    [OBJECT2]
        [A]
            &lt;Key1&gt;1&lt;/Key1&gt;
            &lt;Key2&gt;2&lt;/Key2&gt;
            &lt;Key3&gt;3&lt;/Key3&gt;
        [/A]
        [B]
            &lt;Key1&gt;4&lt;/Key1&gt;
            &lt;Key2&gt;5&lt;/Key2&gt;
        [/B]
    [/OBJECT2]
    [/Y]
    [Z]
        [OBJECT1]
        [A]
            &lt;Key1&gt;7&lt;/Key1&gt;
            &lt;Key2&gt;8&lt;/Key2&gt;
            &lt;Key2&gt;9&lt;/Key2&gt;
            [/A]
        [/OBJECT1]
        [OBJECT2]
        [A]
            &lt;Key1&gt;15&lt;/Key1&gt;
            &lt;Key2&gt;18&lt;/Key2&gt;
        [/A]
        [/OBJECT2]
    [/Z]
[/X]
</code></pre>
