-
DTD to allow mixed content.
I have a DTD that looks like this
Code:
<!ELEMENT question (question_notes?, (input_textarea? | input_checkboxmore* | input_textbox? | input_checkbox* | input_radio? | grid? | grid_expandable?))>
<!ATTLIST question title CDATA #REQUIRED>
As you can see the question element optionally contain a question_notes element, and must contain one of the other elements specified.
The problem is that I want to allow mixed content in my question element. For example :-
Code:
<question>
<question_notes />
<input_checkbox />
<input_checkboxmore />
<input_checkbox />
<input_checkboxmore />
<input_checkbox />
<input_textarea />
<input_checkbox />
</question>
The optional elements specified in my DTD are mutually exclusive i.e. once I specify my first input_checkbox element in the example above, all the other elements that aren't input_checkbox element become invalid.
How can I allow the question element to contain mixed elements?
Last edited by neotoxic; 06-23-2006 at 05:22 AM.
-
First off it sounds like this is a kinda strage XML construction, what would something look like if it had all this stuff mashed together?
You could just do the ugly thing and expand it out, something like:
Code:
<!ELEMENT question (question_notes?, (input_textarea, (input_checkboxmore* | input_textbox? | input_checkbox* | input_radio? | grid? | grid_expandable?)) | (input_checkboxmore+, ...))>
<!ATTLIST question title CDATA #REQUIRED>
This gets ugly, but its the only way that I can think of to specify everything that you want to. You might also consider using XML Schema, it might be a little more expressive, but I have forgotten some of the details. (http://www.w3schools.com/schema/default.asp)
Hope this helps.
~evlich
-
What I am trying to create is an XML document that contains the structure of an online form. The form could be presented in one of 3 different ways. The XML documents are parsed with the appropriate XSLT document to create the XHTML for the user.
I understand that XML documents are supposed to be containers for data, and not as such infer any presentation order to that structure. This is probably why I am having a problem with my forms.
I have some node entities that represent user input fields in my form (i.e. input_checkboxmore, input_textbox, input_checkbox, grid grid_expandable etc) . Each one has its own unique requirements in terms of definition.
I also have a question node that represents a question in my form. In most cases each question has only one type of user input node associated with it. However there are a number of times when I will need to have multiple types of user response within a single question node.
As mentioned before my DTD currently doesnt allow this.
Is there a better way to approach this problem, or is there a way to allow any number of nodes, of a certain type, in any order to appear within a node?
It is a limitation of the transform mechanism that I use a DTD, and not an XML Schema.
Any and all suggestions welcome.
-
OK.. well I have solved my problem, although I am still open to suggestions.
My solution was to create a new entity called user_input. The question entity was modified to allow 0 or many user_input child entities. The user_input definition allowed all the nodes previously allowed under the question entity.
As I have wrapped the mixed content up into a single repeatable entity the code no conforms to the DTD correctly.
Now I have code that looks like this.
Code:
<question>
<user_input>
<question_notes />
</user_input>
<user_input>
<input_checkbox />
</user_input>
<user_input>
<input_checkboxmore />
</user_input>
<user_input>
<input_checkbox />
</user_input>
<user_input>
<input_checkboxmore />
</user_input>
<user_input>
<input_checkbox />
</user_input>
<user_input>
<input_textarea />
</user_input>
<user_input>
<input_checkbox />
</user_input>
</question>
-
What types of inputs are these, you might be able to handle them using attributes or nested tags. For example, checkbox and radio box could be generalized to selection with an attribute for allowMultiple. Also, text input can be generalized to allowMultiline. I'm not exactly sure what your other ones do, but maybe you can find some way to simplify it.
Good luck.
~evlich
-
Good Question, Use Schema's
This is one of the many reasons to NOT use DTDs. Use Schema's instead, wherever possible. DTD's were replaced by schemas over 5 years ago!
Similar Threads
-
By rafael sanzio in forum VB Classic
Replies: 0
Last Post: 10-17-2005, 01:53 PM
-
Replies: 0
Last Post: 03-23-2001, 12:17 PM
-
Replies: 2
Last Post: 03-16-2001, 09:56 AM
-
By Ning in forum Database
Replies: 0
Last Post: 03-14-2001, 02:03 PM
-
By Benoît Sévigny in forum XML
Replies: 0
Last Post: 08-29-2000, 10:38 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks