Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > [DTD] defining elements depending on attribute

Reply
Thread Tools

[DTD] defining elements depending on attribute

 
 
Ekim
Guest
Posts: n/a
 
      12-01-2004
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


 
Reply With Quote
 
 
 
 
Jan Roland Eriksson
Guest
Posts: n/a
 
      12-01-2004
On Wed, 1 Dec 2004 21:57:06 +0100, "Ekim" <(E-Mail Removed)>
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


 
Reply With Quote
 
 
 
 
Arjun Ray
Guest
Posts: n/a
 
      12-12-2004
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.

 
Reply With Quote
 
Peter Flynn
Guest
Posts: n/a
 
      12-18-2004
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_
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XML W3C Schema, check excistence of attribute depending on otherattributes RolfK XML 2 09-10-2008 02:22 PM
Defining Your Own Attribute in an HTML Tag Herman HTML 2 06-06-2006 08:34 AM
picking value of one attribute based on a child elements attribute? XPath? vjethava@gmail.com XML 2 03-06-2006 05:19 AM
Defining a property with the DontEnum attribute Howard Jess Javascript 16 11-26-2005 05:28 PM
defining or not defining destructors johny smith C++ 8 07-02-2004 08:51 AM



Advertisments