Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   [DTD] defining elements depending on attribute (http://www.velocityreviews.com/forums/t168342-dtd-defining-elements-depending-on-attribute.html)

Ekim 12-01-2004 08:57 PM

[DTD] defining elements depending on attribute
 
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



Jan Roland Eriksson 12-01-2004 09:41 PM

Re: [DTD] defining elements depending on attribute
 
On Wed, 1 Dec 2004 21:57:06 +0100, "Ekim" <the.newsletter@gmx.net>
wrote:

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

--
Rex



Arjun Ray 12-12-2004 05:33 AM

Re: [DTD] defining elements depending on attribute
 
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.


Peter Flynn 12-18-2004 12:20 AM

Re: [DTD] defining elements depending on attribute
 
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_


All times are GMT. The time now is 06:54 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.