Volker Hetzer wrote:
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>
In DTD, all you can do is to allow SOME text to appear in <xkoordetc.
elements.
<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