473,385 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

[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
Jul 20 '05 #1
2 1285
On Wed, 1 Dec 2004 21:57:06 +0100, "Ekim" <th************@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
Jul 20 '05 #2
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.

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Simon Brooke | last post by:
Test Test HTML file Test file to observe effect of DTD declaration on XSL processing.
2
by: wzhang | last post by:
Hi, I would like to add some custom elements to svg files and also some custom attributes to certain svg elements. Should I create a DTD to include the cumtom elements and attributes? ...
4
by: Doug Estep | last post by:
Below is a sample of my XML… <MetaData> <Table name="mytable"> <PrimaryKey name="pk"><Column name="mycolumn"/></PrimaryKey> </Table> </MetaData> <Sequencer> <Table name="mytable">
2
by: Ritu | last post by:
Hello Folks, I am struggling to convert an existing DTD file to the XSD format. I encountered some problems and was hoping someone could help me out here. I am using XMLspy to create the...
1
by: johnmack | last post by:
In my XML instances I want to use the XLink namespace for attributes on certain elements. I'm having quite a hard time determining how to reflect this properly in my DTD and XML instances. In...
3
by: Girish Sharma | last post by:
I'm new to using XML. I am currently required to use dtd's rather than schemas. I have some questions about what is considered appropriate design with a dtd. It seems that none of the following are...
3
by: Volker Hetzer | last post by:
Hi! I'm pretty new to all this XML/SGML stuff and I'd like to know how you decide, what values go in an attribute and what values in the text part of a node. Consider a point, which has an x value...
4
by: Ross Presser | last post by:
I'm feeling very stupid about this ... pdf2html (http://pdf2html.sourceforge.net) is an app that reads a PDF and can generate HTML or XML; in my case I'm using the XML. The PDF I'm working with...
3
by: Eric Lilja | last post by:
Hello, this is an xml-file with a nested DTD. It validates, test-1- with-dtd.xml: <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE persons > <persons> <person name="Eric Lilja" /> </persons>
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.