How would you design an XML file to store key-value pairs?

Discussion in 'XML' started by Ramon F Herrera, Jul 26, 2011.

  1. (newbie alert)

    I have a bunch of key-value pairs (both of which with spaces) and have
    been trying different ways to encode them in XML.

    For instance,

    "Name of Client" => "John Smith"

    I am not posting my versions, intentionally. Would like to see yours
    first. :)

    TIA!

    -Ramon
     
    Ramon F Herrera, Jul 26, 2011
    #1
    1. Advertising

  2. That's essentially the standard "would you rather use attributes or
    children values" question, since you don't care about the ordering of
    the pairs and both are simple strings.

    If you think either will eventually want to be divided into
    sub-structures, or if you think that other values you add later may want
    to consider their order relative to these meaningful, child elements are
    probably the way to go. If not, attributes or child text may be a trifle
    more human-readable, and are a trifle more compact in the XML text form.

    It really boils down to picking the one that reflects how you want code
    developers to think about the data. All of these are entirely reasonable:

    <pair key="string1" value="string2"/>
    <pair><key>string1</key><value>string2</value></pair>
    <pair key="string1"><value>string2</value></pair>
    <pair key="string1">string2</pair>

    (The fact that you need to allow spaces eliminates the option of having
    the key be the element name rather than "pair", which I'd otherwise
    include in this list.)

    Note that this is exactly the same set of decisions you have to make
    when designing data structures in a programming languages. Is a given
    value a named data field of the object or struct, or is it contained in
    another object or struct owned by this one? Or, for that matter, is it
    stored somewhere else entirely and just pointed to? All are defensible
    decisions, depending on how you want to model the data now, how much you
    want that model to agree with other models, and what your plans are for
    the future.

    --
    Joe Kesselman,
    http://www.love-song-productions.com/people/keshlam/index.html

    {} ASCII Ribbon Campaign | "may'ron DaroQbe'chugh vaj bIrIQbej" --
    /\ Stamp out HTML mail! | "Put down the squeezebox & nobody gets hurt."
     
    Joe Kesselman, Jul 26, 2011
    #2
    1. Advertising

  3. Note that if the keys are unique, there *may* be an advantage to making
    them attributes and declaring them in the DTD or schema as ID
    attributes. Some systems may build ID lookup tables to expedite
    retrieving things by ID. (On the other hand, others may build lookup
    tables for other things too; depends on how much they know about what
    you will want to do and how clever they are and how much time and space
    they can afford to spend on speculative/cached computation.)
     
    Joe Kesselman, Jul 26, 2011
    #3
  4. On Jul 26, 10:26 am, Joe Kesselman <>
    wrote:
    > That's essentially the standard "would you rather use attributes or
    > children values" question, since you don't care about the ordering of
    > the pairs and both are simple strings.
    >
    > If you think either will eventually want to be divided into
    > sub-structures, or if you think that other values you add later may want
    > to consider their order relative to these meaningful, child elements are
    > probably the way to go. If not, attributes or child text may be a trifle
    > more human-readable, and are a trifle more compact in the XML text form.
    >
    > It really boils down to picking the one that reflects how you want code
    > developers to think about the data. All of these are entirely reasonable:
    >
    > <pair key="string1" value="string2"/>
    > <pair><key>string1</key><value>string2</value></pair>
    > <pair key="string1"><value>string2</value></pair>
    > <pair key="string1">string2</pair>
    >
    > (The fact that you need to allow spaces eliminates the option of having
    > the key be the element name rather than "pair", which I'd otherwise
    > include in this list.)
    >
    > Note that this is exactly the same set of decisions you have to make
    > when designing data structures in a programming languages. Is a given
    > value a named data field of the object or struct, or is it contained in
    > another object or struct owned by this one? Or, for that matter, is it
    > stored somewhere else entirely and just pointed to? All are defensible
    > decisions, depending on how you want to model the data now, how much you
    > want that model to agree with other models, and what your plans are for
    > the future.
    >
    > --
    > Joe Kesselman,http://www.love-song-productions.com/people/keshlam/index.html
    >
    > {} ASCII Ribbon Campaign | "may'ron DaroQbe'chugh vaj bIrIQbej" --
    > /\ Stamp out HTML mail!  | "Put down the squeezebox & nobody gets hurt."


    Thanks, Joe!

    It was highly instructive.

    -Ramon
     
    Cambridge Ray, Jul 27, 2011
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Equis Uno
    Replies:
    6
    Views:
    506
    Equis Uno
    Mar 1, 2004
  2. Florian Lindner

    key - key pairs

    Florian Lindner, Jun 23, 2005, in forum: Python
    Replies:
    8
    Views:
    555
    Paul McGuire
    Jun 24, 2005
  3. Markus Dehmann

    key-value pairs: key consists of 3 ints

    Markus Dehmann, Jan 15, 2006, in forum: C++
    Replies:
    13
    Views:
    638
    Richard Herring
    Jan 23, 2006
  4. Diwa
    Replies:
    0
    Views:
    998
  5. Antonio Quinonez
    Replies:
    2
    Views:
    176
    Antonio Quinonez
    Aug 14, 2003
Loading...

Share This Page