I have this XML structure that I wish to construct in JSON format using JavaScript – preferably using dot notation all the way if possible. ๐
Here is the XML – note this is a pseudo structure, to keep it simple! ๐
<Items>
<Item>
<Name>Item 1</Name>
<SubItems>
<Item>
<Name>Sub Item 1</Name>
</Item>
</SubItems>
</Item>
<Item>
<Name>Item 2</Name>
</Item>
</Items>
So, when I convert my JSON to XML (on the server), the output should be like above.
I need help getting started with this. I Google’d around and I couldn’t find any examples on how to do this.
Thanks in advance!
EDIT: I am using NewtonSoft JSON for .NET to convert from JSON to XML!
EDIT 2: Ok, I figured out the Raw JSON structure to get the convertion to XML right – here it is:
var json = {
"Items":
{
"Item":
[
{
"Name": "Test 1" ,
"SubItems":
{
"Item":
[
{
"Name":"Test 1"
},
{
"Name":"Test 2"
}
]
}
},
{
"Name":"Test 2"
}
]
}
};
That will produce the exact same XML structure as defined above.
Now, how would I go about building this structure using dot notation?
EDIT 3: With the help of Nikhil & Darin, I figured it out, however this only answers the pseudo-question. However I will mark this as answered and create a new question. ๐
EDIT 4: I posted my extension to the marked answer. ๐
Output of the above code is
that should do it ๐