473,769 Members | 2,143 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[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 1300
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
2134
by: Simon Brooke | last post by:
Test Test HTML file Test file to observe effect of DTD declaration on XSL processing.
2
1698
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? <!ATTLIST {element name} {attribute name} {type} {default option}>. If I do need to create a DTD, then how do I specify the element name in custom attributes declaration since the element itself is in SVG? For exampe, I would like to do this: <svg...
4
6783
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
1354
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 schema. My original DTD statement looks like this
1
2073
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 my instance, to declare the namespace, I have this on my root element: <root xmlns:xlink="http://www.w3.org/1999/xlink"> ... <mylink xlink:href="http://foo.com"> ....
3
1110
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 enforced by the dtd during a standard validation: 1. Using the value of attributes to constrain which of the optional child elements are allowed to be used. 2. Restricting the number of a particular element that can exist with a particular...
3
1065
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 an y value and a z value. I see several possibilities: <point x=1, y=2, z=3 /> <point> <xkoord>1</xkoord>
4
3378
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 is a concatenation of many reports; my objective is to find the first page of each report, which I've discovered can be found in this particular instance by looking for an xml element with a particular attribute "left" equal to 277. So I want...
3
3102
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
9583
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9990
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9860
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8869
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6668
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5445
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3955
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3560
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.