Which one is better...

M

mathieu

'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
 
P

Philippe Poulard

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 said:
Thanks for comments
-Mathieu


--
Cordialement,

///
(. .)
--------ooO--(_)--Ooo--------
| Philippe Poulard |
-----------------------------
http://reflex.gforge.inria.fr/
Have the RefleX !
 
J

Joseph Kesselman

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top