[DTD] defining elements depending on attribute

E

Ekim

hello,

I wanna create a new DTD for a protocol - therefore I have one question:

is there a way to define elements depending on a special attribute-value?
I guess I've confused you so far, so that's what I really mean:

I have got an element "sensor":
<!ELEMENT sensor ((longitude, latitude) | (direction, speed))>

This element has an attribute "type":
<!ATTLIST sensor type (GPS | WIND) "GPS">

My question now is, if it is possible that the sub-elements of "sensor" are
"longitude, latitude" only in the case when the type-attribute = "GPS".
When the type-attribute = "WIND", the sub-elements shall exactly be
"direction, speed".

Currently it doesn't matter which value the type-attribute actually has -
the subelements can either be (longitude, latitude) OR (direction, speed).
But I want them only when the attribute is set accordingly.

Do you have an idea how to do that? Is there a way in DTD to specify such
things?

I appreciate any help,

ekim
 
J

Jan Roland Eriksson

I wanna create a new DTD for a protocol - therefore I have one question:
is there a way to define elements depending on a special attribute-value?
I guess I've confused you so far, so that's what I really mean:

I have got an element "sensor":
<!ELEMENT sensor ((longitude, latitude) | (direction, speed))>

This element has an attribute "type":
<!ATTLIST sensor type (GPS | WIND) "GPS">

My question now is, if it is possible that the sub-elements of "sensor" are
"longitude, latitude" only in the case when the type-attribute = "GPS".
When the type-attribute = "WIND", the sub-elements shall exactly be
"direction, speed".

No. An attribute specification can not be directly used to specify the
content model of an element that the attribute belongs to.

Chose a different approach to your problem. (Architectural processing
comes to mind but I have not investigated that approach any further at
this time)
 
A

Arjun Ray

I have got an element "sensor":
<!ELEMENT sensor ((longitude, latitude) | (direction, speed))>

This element has an attribute "type": <!ATTLIST sensor type (GPS | WIND)
"GPS">

My question now is, if it is possible that the sub-elements of "sensor"
are "longitude, latitude" only in the case when the type-attribute =
"GPS". When the type-attribute = "WIND", the sub-elements shall exactly be
"direction, speed".

No, it is not possible.

A lot of the time, a "type" attribute is a good indication of a flawed
design, typically where the element type - hey, note that word! - is too
general for the intended structural purpose.

You can have what you want by replacing the "sensor" element type, which
is too general, with two more specific element types, e.g.

<!ELEMENT gps-sensor (longitude, latitude) >
<!ELEMENT wind-sensor (direction, speed) >

And wherever 'sensor' appears in a content model, replace it with

sensor => (gps-sensor | wind-sensor)

Note also that you can dispense with the 'type' attribute, too.
 
P

Peter Flynn

Arjun said:
No, it is not possible.

A lot of the time, a "type" attribute is a good indication of a flawed
design, typically where the element type - hey, note that word! - is too
general for the intended structural purpose.

You can have what you want by replacing the "sensor" element type, which
is too general, with two more specific element types, e.g.

<!ELEMENT gps-sensor (longitude, latitude) >
<!ELEMENT wind-sensor (direction, speed) >

And wherever 'sensor' appears in a content model, replace it with

sensor => (gps-sensor | wind-sensor)

Note also that you can dispense with the 'type' attribute, too.

Even easier,

<!ELEMENT sensor (wind|gps)>
<!ELEMENT wind (direction|speed)>
<!ELEMENT gps (longitude|latitude)>

///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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top