Hey everyone!
I'm currently in the process of developing a UI toolkit as a part of a larger project of mine. The idea is that this toolkit takes some input in the form of either JSON or XML and turns it into a user interface. So here's the question: Should users define their user interfaces using JSON or XML?
XML seems to be the most familiar to developers considering that most other UI markup solutions use XML, namely HTML and WPF/XAML. However, JSON would be easier to parse, I'd be able to directly import those data structures into my code for processing, instead of having to move elements the parsed XML to new data structures. Thus it'd just be easier to do it with JSON. Thing is, developers might get kinda irked that their UI is being defined in JSON. It's not the most readable or concise.
I then thought that JSON might not really be the way to go, but regular javascript where I can use constructors. This isn't really "safe" to parse (you'd have to use eval), but I'm not sure if that matters to me.
I'll give some examples of what I mean:
XML:
<applicationUI>
<layoutContainer behavior="flow">
<textbox name="textbox1" auxContentType="icon" auxContent="icon-alert">Hello</textbox>
<break />
<button width="200">Hello</button>
</layoutContainer>
</applicationUI>
JSON:
{
content: [
{
type: 'layoutContainer',
behavior: 'flow',
content: [
{
type: 'textbox',
name: 'textbox1',
auxContentType: 'icon',
auxContent: 'icon-alert',
content: 'Hello',
width: '100%'
},
{ type: 'break' },
{
type: 'button',
content: 'Hello',
width: 200
}
]
}
]
}
JS:
new ApplicationUI({
content: [
new Textbox({
name: 'textbox1',
auxContentType: 'icon',
auxContent: 'icon-alert',
content: 'Hello',
width: '100%'
}),
new Break(),
new Button({
content: 'Hello',
width: 200
})
]
});
Which one do you guys think would be the best to go with? I'm leaning toward #3 but all of them have their positive and negative aspects.