1

First some background, I am writing an application in C# that will allow a user to easily specify a series of programs, commands, or websites with arguments and window positions, then launch them with a single click. I'm trying to decide if it would be better to use XML or JSON to encode the user files.

Here's my preliminary designs for the data structures :

XML

<AutoLauncher>
    <Program>
        <Location>C:\example.exe</Location>
        <Arguments>
            <Argument>
                <Key>a</Key>
                <Value>true</Value>
            </Argument>
        </Arguments>
        <Position>
            <Monitor>1</Monitor>
            <X>0</X>
            <Y>0</Y>
        </Position>
    </Program>
    <Cmd>
        <Command>example</Command>
        <Arguments>...</Arguments>
        <Position>...</Position>
    </Cmd>
    <Website>
        <Url>www.example.com</Url>
        <Browser>Default</Browser>
        <Arguments>...</Arguments>
        <Position>...</Position>
    </Website>
</AutoLauncher>

JSON

{
  Programs: [
    { Location: "C:\example.exe",
      Arguments: [
        {Key: "a", Value: true}
      ],
      Position: {
        Monitor: 1,
        X: 0,
        Y: 0
      }
    }
  ],
  Commands:[
    { Command: "example",
      Arguments:[...],
      Position: {...}
  ],
  Websites: [
    { Url: "www.example.com",
      Browser: "default",
      Arguments: [...],
      Position: {...}
  ]
}

Note: I used ... in the arguments and position of the commands and websites as the structure would be exactly like the programs structure.

Which data structure would be best (Or is there something else that would be better)?

binary-idiot
  • 119
  • 1
  • 9

2 Answers2

2

It's surely going to be covered in other links, but your XML sample is essentially identical to your JSON sample. With JSON, that is pretty much all you get. With XML, you can be a little more expressive. For example:

<!-- My AutoLauncher Settings : Last updated 2018-04-16 -->
<AutoLauncher>

    <Program Location="C:\example.exe" Monitor="1" X="0" Y="0">
        <Arguments>
            <Argument Key="a" Value="true" />
        </Arguments>
    </Program>

    <!-- Temporarily disable this one. I'll fix later.
    <Cmd Command="example" Monitor="1" X="0" Y="0">
        <Arguments>...</Arguments>
        <Position>...</Position>
    </Cmd>
    -->

    <!-- I want to launch this because... -->
    <Website Url="www.example.com" Browser="Default" Monitor="1" X="0" Y="0">
        <Arguments>...</Arguments>
    </Website>
</AutoLauncher>

JSON has it's uses. But for configuration (particular user-managed), I prefer XML.

Nigel Whatling
  • 2,371
  • 1
  • 16
  • 22
  • I figured you could do more with xml, however at the moment I'm fairly new to it. It is also of note that the xml won't be directly written by the user but will be generated, I want to use a fui so that people who don't know any coding (Or xml) can use it. – binary-idiot Apr 16 '18 at 14:56
0

JSON’s structure is intuitive, making it easy to read and map directly to domain objects in whatever programming language is being used.

TheDude
  • 257
  • 1
  • 9
  • 1
    Intuitive is subjective. One could make the same argument about XML; based on which you're used to working with. Furthermore, XML data can be mapped directly to domain objects in pretty much the exact same way as you'd map JSON data (by either using property attributes or manually handling the (de)serialization). – Flater Apr 16 '18 at 13:43