Custom string format to xml help needed. Java and C#.
[Node(X)][CHILD0(Y)][OBJECT1(A)][Key1(1)][Key2(2)]
[Node(X)][CHILD0(Y)][OBJECT1(B)][Key1(1)][Key2(2)][Key3(3)]
[Node(X)][CHILD0(Y)][OBJECT1(C)][Key1(4)]
[Node(X)][CHILD0(Y)][OBJECT2(A)][Key1(1)][Key2(2)][Key3(3)]
[Node(X)][CHILD0(Y)][OBJECT2(B)][Key1(4)][Key2(5)]
[Node(X)][CHILD1(Z)][OBJECT1(A)][Key1(7)][Key2(8)][Key3(9)]
[Node(X)][CHILD1(Z)][OBJECT2(A)][Key1(15)][Key2(18)]
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
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.
[X]
[Y]
[OBJECT1]
[A]
<Key1>1</Key1>
<Key2>2</Key2>
[/A]
[B]
<Key1>2</Key1>
<Key2>2</Key2>
<Key3>3</Key3>
[/B]
[C]
<Key1>4</Key1>
[/C]
[/OBJECT1]
[OBJECT2]
[A]
<Key1>1</Key1>
<Key2>2</Key2>
<Key3>3</Key3>
[/A]
[B]
<Key1>4</Key1>
<Key2>5</Key2>
[/B]
[/OBJECT2]
[/Y]
[Z]
[OBJECT1]
[A]
<Key1>7</Key1>
<Key2>8</Key2>
<Key2>9</Key2>
[/A]
[/OBJECT1]
[OBJECT2]
[A]
<Key1>15</Key1>
<Key2>18</Key2>
[/A]
[/OBJECT2]
[/Z]
[/X]
Here’s a parser class for your purpose:
Use it like this:
Output:
Go from here and optimize it a little, for example if you don’t want repeated
<X>...</X>nodes.