Complex attribute defaults?

  • Thread starter Robert William Vesterman
  • Start date
R

Robert William Vesterman

Is there a way to say, in a DTD things like:

(1) The default value of attribute X is the value of attribute Y?

(2) The default value of attribute X is the value of attribute Y
appended by the text "BLAH"?

(3) The default value of attribute X is "BLAH" if attribute Y has
value "BLING", or "BOING" otherwise?

(4) The default value of attribute X is "BLAH" if attribute Y is
present, or "BOING" otherwise?

Or various other possibilities beyond the simple "the default value is
such-and-such and that's all there is to it"?

If I need such concepts, and it's not possible, obviously I have to do
them at the application level, and pretend at the XML level that
they're just "#IMPLIED". Is that somehow considered an invalid,
incorrect, impure, evil, or otherwise negative thing to do?

Thanks,

Bob Vesterman.
 
D

David Carlisle

Is there a way to say, in a DTD things like:
... No

If I need such concepts, and it's not possible, obviously I have to do
them at the application level, and pretend at the XML level that
they're just "#IMPLIED". Is that somehow considered an invalid,
incorrect, impure, evil, or otherwise negative thing to do?

It's the way life is. It's certainly not invalid, I leave others to
judge harder concepts such as impurity or evil:)

David
 
P

Peter Flynn

Robert said:
Is there a way to say, in a DTD things like:

(1) The default value of attribute X is the value of attribute Y?

In a *DTD*, yes, but only by hardcoding it

<!ATTLIST foo X (a|b|c) "c" Y (c) "c">

A default token list value must be a literal: it can't be a parameter
entity, so it's not possible to hard-code it.

But I find it hard to imagine a circumstance where you want to do this.
Can you explain more? I think you mean that you want to do this in an
XML document instance.
(2) The default value of attribute X is the value of attribute Y
appended by the text "BLAH"?

The same answer.
(3) The default value of attribute X is "BLAH" if attribute Y has
value "BLING", or "BOING" otherwise?

(4) The default value of attribute X is "BLAH" if attribute Y is
present, or "BOING" otherwise?

No. You have to use a Schema if you want this level of validation.
Or various other possibilities beyond the simple "the default value is
such-and-such and that's all there is to it"?

If I need such concepts, and it's not possible, obviously I have to do
them at the application level, and pretend at the XML level that
they're just "#IMPLIED". Is that somehow considered an invalid,
incorrect, impure, evil, or otherwise negative thing to do?

No, just that DTDs were designed for TEXT documents, not DATA, so
cross-validation of attribute values was not an issue, as it arises
so rarely in normal text documents.

///Peter
 

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,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top