dtd design heuristics?

V

Volker Hetzer

Hi!
I'm pretty new to all this XML/SGML stuff and I'd like to know how you
decide, what values go in an attribute and what values in the text part of a node.
Consider a point, which has an x value an y value and a z value.
I see several possibilities:

<point x=1, y=2, z=3 />

<point>
<xkoord>1</xkoord>
<ykoord>2</ykoord>
<zkoord>3</zkoord>
</point>

<point>
<koord axis=x>1</koord>
...
</point>

<point>
<koord axis=x value=1 />
...
</point>

What do you think is best?
Generally, how does one decide which values to put in a sub node and which one into an attribute?

Lots of Greetings!
Volker
 
S

Stefan Ram

Volker Hetzer said:
Generally, how does one decide which values to put in a sub
node and which one into an attribute?

When a new document type is to be defined, when should one
choose child elements and when attributes?

The criterion that makes sense regarding the meaning can not
be used in XML due to syntactic restrictions.

An element is describing something. A description is an
assertion. An assertion might contain unary predicates or
binary relations.

Comparing this structure of assertions with the structure
of XML, it seems to be natural to represent unary predicates
with types and binary relations with attributes.

Say, "x" is a rose and belongs to Jack. The assertion is:

rose( x ) ^ owner( x, "Jack" )

This is written in XML as:

<rose owner="Jack" />

Thus, my answer would be: use element types for unary
predicates and attributes for binary relations.

Unfortunately, in XML, this is not always possible, because
in XML:

- there might be at most one type per element,

- there might be at most one attribute value per attribute
name, and

- attribute values are not allowed to be structured in
XML.

Therefore, the designers of XML document types are forced to
abuse element /types/ in order to describe the /relation/
of an element to its parent element.

This /is/ an abuse, because the designation "element type"
obviously is supposed to give the /type of an element/,
i.e., a property which is intrinsic to the element alone
and has nothing to do with its relation to other elements.

The document type designers, however, are being forced to
commit this abuse, to reinvent poorly the missing structured
attribute values using the means of XML. If a rose has two
owners, the following element is not allowed in XML:

<rose owner="Jack" owner="Jill" />

One is made to use representations such as the following:

<rose>
<owner>Jack</owner>
<owner>Jill</owner></rose>

Here the notion "element type" suggests that it is marked
that Jack is "an owner", in the sense that "owner" is
supposed to be the type (the kind) of Jack.

The intention of the author, however, is that "owner" is
supposed to give the /relation/ to the containing element
"rose". This is the natural field of application for
attributes, as the meaning of the word "attribute" outside
of XML clearly indicates, but it is not possible to
always use attributes for this purpose in XML.

An alternative solution might be the following notation.

<rose owner="Alexander Marie" />

Here a /new/ mini language (not XML anymore) is used within
an attribute value, which, of course, can not be checked
anymore by XML validators. This is really done so, for
example, in XHTML, where classes are written this way.

So in its most prominent XML application XHTML, the W3C
has to abandon XML even to write class attributes. This
is not such a good accomplishment given that the W3C
was able to use the experience made with SGML and HTML
when designing XML.

The needless restrictions of XML inhibit the meaningful
use of syntax. This makes many document type designers
wonder, when attributes and when elements
should be used, which actually is an evidence of
incapacity for the design of XML: XML does not have many
more notations than these two: attributes and elements.
And now the W3C failed to give even these two
notations a clear and meaningful dedication!

Without the restrictions described, XML alone would have
nearly the expressive power of RDF/XML, which has to repair
painfully some of the errors made in the XML-design.

Now, some "experts" recommend to /always/ use subelements,
because one can never know, whether an attribute value
that seems to be unstructured today might need to become
structured tomorrow. Other experts recommend to use
attributes only when one is quite confident that they
never will need to be structured. This recommendation
does not even try to make a sense out of attributes,
but just explains how to circumvent the obstacles
the W3C has built into XML.

Others recommend to use attributes for something they
call "metadata". They ignore that this limits "metadata"
to unstructured values.

Others use an XML editor that happens to make the input of
attributes more comfortable than the input of elements and
seriously suggest, therefore, to use as many attributes as
possible.

Still others have studied how to use CSS to format XML
documents and are using this to give recommendations about
when to use attributes and when to use subelements. (So
that the resulting document can be formatted most easily
with CSS.)

Of course: Mixing all these criteria (structured vs.
unstructured, data vs. "metadata", by CSS, by the ease of
editing, ...) often will give conflicting recommendations.

Certain other notations than XML have solved the problem
by either omitting attributes altogether or by allowing
structured attributes.
 
S

Soren Kuula

Volker said:
Hi!
I'm pretty new to all this XML/SGML stuff and I'd like to know how you
decide, what values go in an attribute and what values in the text part
of a node.
Consider a point, which has an x value an y value and a z value.
I see several possibilities:

In either case, in XML you will need to quote (' or ") your attribute
values.
<point x=1, y=2, z=3 />

-- and no commas between the attrubutes ;)

In DTD you can data-type your attribute values but not text nodes. I
can't remember if there is an integer data type.

If you upgrade to XML Schema, there definitily are some numeral data
types, and you can use them on both attribute values and text nodes.
<point>
<xkoord>1</xkoord>
<ykoord>2</ykoord>
<zkoord>3</zkoord>
</point>

<point>
<koord axis=x>1</koord>
...
</point>

<point>
<koord axis=x value=1 />
...
</point>

In DTD, you can define an enumeration of x, y, z for the attribute
value. That is a nice way to go, if you want separate koord elements.
What do you think is best?

If you are sure to stay in 3D, and that the coordinates are always named
x, y, z, I would go for the first one. Others would not.
Generally, how does one decide which values to put in a sub node and
which one into an attribute?

There is no conclusion to that. Some people think attributes are for
metedata, and text nodes are for other data.

If you change your mind about your design, there is a nice transform
language called xslt that can transform from either of your formats to
any of the other.

Søren
 
V

Volker Hetzer

Soren said:
Volker Hetzer wrote:
If you are sure to stay in 3D, and that the coordinates are always named
x, y, z, I would go for the first one.
Ok, so will I. The typing is nice.
There is no conclusion to that. Some people think attributes are for
metedata, and text nodes are for other data.

If you change your mind about your design, there is a nice transform
language called xslt that can transform from either of your formats to
any of the other.
Ok.

Thanks a lot to all who responded!
Volker
 

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
474,005
Messages
2,570,264
Members
46,859
Latest member
HeidiAtkin

Latest Threads

Top