XML Dom: storing key/value pairs

xml

Solution

The default way of saving XML files is Way 2, as a lot of XML files use that markup.

But Personally I prefer Way 1 for markup over the others.

It produces way smaller files in terms to readability and linecount, gives a good overview of the items contained in another, bigger element and you don't have to bother creating an end-element tag for each item used in the file (except the container items).

But at the ent of the day, it comes to what YOU prefer and are comfortable with.

Problem

I am new to dealing with XML and I have to store key/value pairs. Is there a preferred way of doing this? Here are a few possibilities I could come up with: Way 1 ``` <item key="k1" value="val1" /> <item key="k2" value="val2" /> <item key="k3" value="val3" /> ``` Way 2 ``` <item><key>k1</key><value>val1</value></item> <item><key>k2</key><value>val2</value></item> <item><key>k3</key><value>val3</value></item> ``` Way 3 ``` <key name="k1">val1</key> <key name="k2">val2</key> <key name="k3">val3</key> ``` Thanks. update: In the meantime I have found this: http://www.ibm.com/developerworks/xml/library/x-eleatt.html

Original source