• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on DTD test from XML Exam List

 
Scott Collens
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a question regarding 2 questions on the DTD test located in Java Ranch's XML Exam List.
Question 1 reads as follows:
1. Which of the following dtd code is valid?
a)<!ELEMENT test (#CDATA)>
b)<!ELEMENT test (#PCDATA)>
c)<!ELEMENT test (#ANY)>
d)<!ELEMENT test (this,that)*>
right
Answer : b

Can someone tell me why 'd' is not valid?
In the 3rd question it seems that answer 'c' is similar to answer 'd' in the first question but the answer says it is valid. Why is this code valid while answer 'd' in question 1 is not.
. Which of the following code is valid?

a)<!DOCTYPE test [ <!ELEMENT test (#PCDATA)>]>
b)<!DOCTYPE test [ <!ELEMENT test.dtd (elm1|elm2|#PCDATA) >]>
c)<!DOCTYPE test [ <!ELEMENT test.dtd (#PCDATA|elm1|elm2)* >]>
d)<!DOCTYPE test [ <!ELEMENT test test (#PCDATA)>]>
e)<!DOCTYPE test [ <!ELEMENT test "test" (#PCDATA)>]>


Thanks....Scott
[This message has been edited by Scott Collens (edited June 27, 2001).]
 
Scott Collens
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have solved half the problem. When using mixed content the elements must be declared as zero or more cardinality, so the parent element can optionally include text or the child elements.
Is it illegal to combine multiple child elements as optional?
So if,
<!ELEMENT A (B,C)*>
You are saying A can include B and C one or more times, but if it does not include one it cannot inlude the other. Isit legal to do this?
Scott
 
Sanjay Mishra
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scot,
The option of the question 1 is confusing.
What I wanted from the question was that u need to declare
the contained elements also in the dtd for the validation.

So the complete code would be:
<!ELEMENT test(this,that)*>
<!ELEMENT this(#PCDATA)>
<!ELEMENT that(#PCDATA)>

For that matter the complete code for the 3rd question should be
c. <!DOCTYPE test [ <!ELEMENT test.dtd (#PCDATA|elm1|elm2)* >]>
<!ELEMENT elm1 (#PCDATA)>
<!ELEMENT elm2 (#PCDATA)>

Is it illegal to combine multiple child elements as optional?
No it is not illegal to combine multiple child elements as optional.
Please refer to w3 specs for further details.
Map, Ajith please correct me as I have been out of touch for quite a long time.
Sanjay
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic