Which one is better...

Discussion in 'XML' started by mathieu, Dec 12, 2007.

  1. mathieu

    mathieu Guest

    'lo there !

    I am a complete newbie in XML and I am pretty sure my question does
    not make a lot of sense but here it goes anwyay.

    Are there any real differences in between:

    <entry group="0000" element="0850" vr="US" vm="1" retired="true"
    version="2">
    <name>Number of Matches</name>
    </entry>

    and

    <entry group="0000" element="0850" vr="US" vm="1" retired="true"
    version="2" name="Number of Matches"/>


    I picked the first solution since 'name' could potentially contains
    non-ASCII characters, double quotes or single quote. It is garantee
    that there is at most one 'name' per 'entry'. name can sometimes be
    unknown. name is typically a very short string, so does this still
    make sense to put it in the character data ?

    Thanks for comments
    -Mathieu
    mathieu, Dec 12, 2007
    #1
    1. Advertising

  2. mathieu a écrit :
    > 'lo there !
    >
    > I am a complete newbie in XML and I am pretty sure my question does
    > not make a lot of sense but here it goes anwyay.
    >
    > Are there any real differences in between:
    >
    > <entry group="0000" element="0850" vr="US" vm="1" retired="true"
    > version="2">
    > <name>Number of Matches</name>
    > </entry>
    >
    > and
    >
    > <entry group="0000" element="0850" vr="US" vm="1" retired="true"
    > version="2" name="Number of Matches"/>
    >
    >
    > I picked the first solution since 'name' could potentially contains
    > non-ASCII characters,


    this is irrelevant since XML relies on Unicode

    double quotes or single quote.

    quotes can be escaped ; the more often, strings that contains single
    quotes are double-quoted, and strings that contains double quotes are
    single-quoted ; strings that contain both must escape those used as
    delimiter ; however if the content of your attribute is created by a
    tool (XML editor, database extraction or whatever) this is a syntax
    consideration that should be transparent

    It is garantee
    > that there is at most one 'name' per 'entry'. name can sometimes be
    > unknown. name is typically a very short string, so does this still
    > make sense to put it in the character data ?


    yes, if you decide it ; but IMHO, an attribute is suitable to your case

    you could also consider this one :
    <entry group="0000" element="0850" vr="US" vm="1" retired="true"
    version="2">Number of Matches</entry>

    >
    > Thanks for comments
    > -Mathieu



    --
    Cordialement,

    ///
    (. .)
    --------ooO--(_)--Ooo--------
    | Philippe Poulard |
    -----------------------------
    http://reflex.gforge.inria.fr/
    Have the RefleX !
    Philippe Poulard, Dec 12, 2007
    #2
    1. Advertising

  3. If you websearch for "elements versus attributes", you'll find a lot of
    discussion of this.

    Attributes have some characteristics that may surprise you, such as
    whitespace normalization. They also (obviously) don't allow the value to
    contain further XML structure, which may be an issue in the future
    depending on how your XML design evolves. Obviously, only one instance
    of an attribute can appear on a single element. Attribute order is
    explicitly not meaningful (and may not be preserved) in XML, which may
    matter to you in some cases.

    The general rule of thumb is to use attributes for simple values which
    describe how the element is to be interpreted, and use elements for
    anything else. But this is very much a judgement call, and a matter of
    taste. So the right answer may be to ask other people who are familiar
    with your data structures which way of thinking about the value makes
    more sense to them, and/or to look at how others have constructed
    similar XML data structures, until you develop a sense of style.


    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
    Joseph Kesselman, Dec 12, 2007
    #3
    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. Mr Alphaque
    Replies:
    14
    Views:
    1,130
    Raymond DeCampo
    Aug 2, 2003
  2. RSB
    Replies:
    0
    Views:
    388
  3. Hafez
    Replies:
    14
    Views:
    710
    Thomas Matthews
    Oct 6, 2003
  4. Himanshu Singh Chauhan

    Memory usage v/s complexity -- which one better?

    Himanshu Singh Chauhan, Jan 24, 2004, in forum: C Programming
    Replies:
    4
    Views:
    410
    Barry Schwarz
    Jan 25, 2004
  5. N/A
    Replies:
    2
    Views:
    1,506
    Alexander Schmolck
    May 11, 2006
Loading...

Share This Page