![]() |
![]() | ![]() | ![]() | Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Re: [DTD] defining elements depending on attribute [Thread Next] Re: [DTD] defining elements depending on attributeTo: NULL Date: 12/18/2004 12:20:00 AM Arjun Ray wrote:
> On Wed, 01 Dec 2004 21:57:06 +0100, Ekim wrote:
>
>> 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.
Even easier,
<!ELEMENT sensor (wind|gps)>
<!ELEMENT wind (direction|speed)>
<!ELEMENT gps (longitude|latitude)>
///Peter
--
"The cat in the box is both a wave and a particle"
-- Terry Pratchett, introducing quantum physics in _The Authentic Cat_
| ![]() | ![]() | ![]() |
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | |||||
|
