473,395 Members | 1,675 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,395 software developers and data experts.

DTD design practices

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 attribute value.

3. Restricting which of some optional child elements are allowed based on
the context (the grand-parent element) of the parent element.

Is creating a dtd that uses these concepts, even though they are not
enforced during standard validation, considered less than optimal design?

Are there commonly used alternatives to the above that do allow for dtd
enforcement?

I'm wondering for example for number 1, instead of attribute values using
optional child elements that correspond with each of those values. Then each
of those child elements can in turn can have the desired child elements for
that situation. It could result in a large number of the "intermediate"
child elements if there are many possible attribute values.

For number 2, is there any way to accomplish that using child elements
instead of attribute values?

For number 3, it seems that changing the parent element into several similar
elements and then using the appropriate one in the correct context. If
carried to an extreme though, there would be no optional child elements at
all - only different parent elements. But my question relates specifically
about always being required to use particular optional child elements based
on context.

Thank you.

Girish Sharma
Mar 23 '06 #1
3 1095
Girish Sharma wrote:
It seems that none of the following are enforced by the dtd
during a standard validation:
DTDs are pretty basic; they provide only structural constraints, not
interactions.
Is creating a dtd that uses these concepts, even though they are not
enforced during standard validation, considered less than optimal design?
Absolutely not; that's entirely reasonable. Remember, the DTD -- or the
schema -- is only the first stage of validation, just enough to provide
some guidance to folks authoring documents or tools to create them.
Think of them as higher-level syntax constraints; your application will
almost always impose semantic constraints on top of those.
Are there commonly used alternatives to the above that do allow for dtd
enforcement?
Different element names can be used for the differently constrained
versions. (or the sort of child-element structuring you suggested). ID
attributes can be used when you need to ensure that an attribute value
is unique in the document (though that's unique for all ID attributes in
the entire document, not just instances of that attribute name). Other
than that... Enforce it in the application.
For number 2, is there any way to accomplish that using child elements
instead of attribute values?
Nope.
For number 3, it seems that changing the parent element into several similar
elements and then using the appropriate one in the correct context. If
carried to an extreme though, there would be no optional child elements at
all - only different parent elements. But my question relates specifically
about always being required to use particular optional child elements based
on context.


If it makes sense semantically for the language you're creating, you can
do it that way. If it doesn't, don't -- enforce in the application
rather than in validation.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Mar 23 '06 #2
Girish Sharma wrote:
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.
No. You have to use a Schema if you want to do this level of validation
at document-creation time.
2. Restricting the number of a particular element that can exist with a
particular attribute value.
Only in that the ID type attribute constrains the values to be unique
per document.
3. Restricting which of some optional child elements are allowed based on
the context (the grand-parent element) of the parent element.
No. Element content models are a flat address space. You can't have
an elements declared to use one content model in one circumstance,
and a different content model in another. But you can probably fake
it using Namespaces :-)
Is creating a dtd that uses these concepts, even though they are not
enforced during standard validation, considered less than optimal design?
It depends on why and where you need to check the values. If you need
to impose the checks during document creation, you'll need a Schema.
If you only need to check them after creation (and route any failed
documents back to the author for amendment) you can write the checks
into a script in XSLT instead.
Are there commonly used alternatives to the above that do allow for dtd
enforcement?
Schemas. Or postprocessing.
I'm wondering for example for number 1, instead of attribute values using
optional child elements that correspond with each of those values. Then each
of those child elements can in turn can have the desired child elements for
that situation. It could result in a large number of the "intermediate"
child elements if there are many possible attribute values.
Yes, that's possible, with the disadvantages you cite.
For number 2, is there any way to accomplish that using child elements
instead of attribute values?
Yes, same as above, but DTDs only allow occurrence indicators
for optionality and multiple occurrence, not counted occurrences.
For number 3, it seems that changing the parent element into several similar
elements and then using the appropriate one in the correct context. If
carried to an extreme though, there would be no optional child elements at
all - only different parent elements. But my question relates specifically
about always being required to use particular optional child elements based
on context.


That's the same concept as before.

In summary, it's probably possible to do what you want, but it would be
pretty clumsy. But if you are constrained to use DTDs that may be your
only option.

///Peter
--
XML FAQ: http://xml.silmaril.ie/
Mar 25 '06 #3
Thank you for the helpful replies to my questions.

Girish Sharma

"Girish Sharma" <re***************@earthlink.net> wrote in message
news:2o*****************@newsread1.news.pas.earthl ink.net...
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 attribute value.

3. Restricting which of some optional child elements are allowed based on
the context (the grand-parent element) of the parent element.

Is creating a dtd that uses these concepts, even though they are not
enforced during standard validation, considered less than optimal design?

Are there commonly used alternatives to the above that do allow for dtd
enforcement?

I'm wondering for example for number 1, instead of attribute values using
optional child elements that correspond with each of those values. Then
each of those child elements can in turn can have the desired child
elements for that situation. It could result in a large number of the
"intermediate" child elements if there are many possible attribute values.

For number 2, is there any way to accomplish that using child elements
instead of attribute values?

For number 3, it seems that changing the parent element into several
similar elements and then using the appropriate one in the correct
context. If carried to an extreme though, there would be no optional child
elements at all - only different parent elements. But my question relates
specifically about always being required to use particular optional child
elements based on context.

Thank you.

Girish Sharma

Apr 1 '06 #4

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

Similar topics

5
by: Chris | last post by:
Having been traumatised many years ago when using MFC/C++ to develop front-end code, I've religiously avoided GUI work since and stuck to back-end / server-side projects. So I'm a bit of a novice...
36
by: Andrea Griffini | last post by:
I did it. I proposed python as the main language for our next CAD/CAM software because I think that it has all the potential needed for it. I'm not sure yet if the decision will get through, but...
13
by: John Salerno | last post by:
Here are a few I'm considering: Design Patterns Explained : A New Perspective on Object-Oriented Design (2nd Edition) (Software Patterns Series) by Alan Shalloway Design Patterns C# by...
7
by: =?Utf-8?B?bWF2cmlja18xMDE=?= | last post by:
Hi, I would like to know more about design patterns and specifically using C#. Can any one recommend a good book? Thanks
12
by: nyathancha | last post by:
Hi, I have a question regarding best practices in database design. In a relational database, is it wise/necessary to sometimes create tables that are not related to other tables through a...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...

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.