Child Element and Attributes ?

P

Pat

Hi all,

In contruction of DTD for a scenario, what are the rules/guildelines
to determine if certain piece of information should be stated as
child element or an attribute?

I read some discussion from the web that one should avoid using
attributes if possible.

Is that true? What's your rules, rather?

Thanks.
 
P

Peter Flynn

Pat said:
Hi all,

In contruction of DTD for a scenario, what are the rules/guidelines
to determine if certain piece of information should be stated as
child element or an attribute?

I read some discussion from the web that one should avoid using
attributes if possible.

Is that true? What's your rules, rather?

No, it's not true, merely some people's opinion. Attributes are there to be
used, and IMHO especially for numeric, categorical, and other discrete data
(see the article in the FAQ at http://www.ucc.ie/xml/#attriborelem).

///Peter
 
J

Jukka K. Korpela

Peter Flynn said:
No, it's not true, merely some people's opinion.

Some opinions are sound, some are not.
Attributes are there
to be used, and IMHO especially for numeric, categorical, and other
discrete data (see the article in the FAQ at
http://www.ucc.ie/xml/#attriborelem).

That's merely some people's opinion. :)

Seriously, generalized markup was designed to be used for textual
content, using attributes to specify properties of elements, not to carry
content. But since XML is already a goofed-up trivialization of
generalized markup, everyone and his brother can play with it as desired.
Some games are just more obscure and risky than others. It's usually the
intended _use_ of markup that will matter.

But just think about this: If you wish, or even need, to indicate changes
in the human language used in a document's content, you can do that for
content, using the xml:lang attribute (and an extra element if needed).
But there's no way to do anything like that for data in attribute values.
(This has been observed e.g. in HTML authoring: since the <img> element,
for embedding an image, was poorly designed to carry the image's textual
replacement in an attribute, alt="...", there is no way to indicate
changes in language in the textual replacement. For such reasons, an
<object> element was designed, for embedding data in general, and it has
the replacement text as the element's content.)
 
A

Arjun Ray

That's merely some people's opinion. :)

Seriously, generalized markup was designed to be used for textual content,
using attributes to specify properties of elements, not to carry content.

+1.

Properties as in qualifications. The element structure should reflect an
analytic decomposition. (This consists of these which in turn consist of
these...) One useful rule of thumb is that elements are (for) nouns, and
attributes are (for) adjectives. (Note the absence of verbs.)

Of course, this is an opinion too, but the lesson - do not put analysable
*content* into attributes - is learned only the hard way.
 

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

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top