File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes Conditional Blocks Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Conditional Blocks" Watch "Conditional Blocks" New topic

Conditional Blocks

Raj Sharma

Joined: Feb 06, 2001
Posts: 12
I want to write conditional blocks in DTD. For Example, the value of Element 1 in block B should be required only if the attribute of Element 1 in block A is "New".
Is there any way to code these kinds of block.
Any other approaches are also welcome.
Sanjay Mishra
Ranch Hand

Joined: Jul 08, 2000
Posts: 84
I never came across where conditional coding was done
it a DTD file.
Mapraputa Is
Leverager of our synergies

Joined: Aug 26, 2000
Posts: 10065
The only way to alternate DTD declarations are INCLUDE and IGNORE sections:
some DTD declarations here

some DTD declarations here

Of course, they do not provide functionality you write about.
They do not provide it for two main reasons: first, DTD is a document-oriented validation tool and your task is really data-oriented. XML Schemas are more data-oriented and provide more sharpened validation tools. Yet not as sharp as you want There is another reason for it. Validation is a multi-layered process. Application may want to delegate some part of it to external tools, such as DTD or Schemas, but there always will be some validity constrains application need to check itself.
DTD, Schemas, or any other validating language define formal �grammar� of your data, and they validate data against formal rules. Like English grammar may say something like �if you have a noun in this place, you can put an adjective before, but you cannot have a preceding adverb�. No grammar will tell you: �if you have a noun �programmer�, you can put �smart� before, but adjectives such as �deep� or �colorful� cannot be legally used�. This is not a formal level, this is a semantic level, and, probably, your application should deal with semantic constraints on its own.
Alternatively, if W3C compliance is not a concern, you can use a language which is specially designed to validate schemas instead of defining them � shematron. It utilizes XPath expressions in its rules.

[This message has been edited by Mapraputa Is (edited June 11, 2001).]

Uncontrolled vocabularies
"I try my best to make *all* my posts nice, even when I feel upset" -- Philippe Maquet
Raj Sharma

Joined: Feb 06, 2001
Posts: 12
Thanks Mapraputa for explaining everything in detail. Really appreciate.
I agree. Here's the link:
subject: Conditional Blocks
It's not a secret anymore!