0

I was writing DTD for the XML given here. http://s3.amazonaws.com/spark-public/db/docs/courses-ID.xml

I could not figure out how to write the Department Element. Here is my DTD code.

<!ELEMENT Course_Catalog (Department+)>
<!ELEMENT Department ---**don't know what to write here**--->
<!ATTLIST Department Code CDATA #REQUIRED Chair IDREF #REQUIRED>
<!ELEMENT Title (#PCDATA)>
<!ELEMENT Course (Title,Description*)>
<!ELEMENT Professor (First_Name,Middle_Initial?,Last_Name)>
<!ELEMENT Lecturer (First_Name,Middle_Initial?,Last_Name)>
<!ATTLIST Course Number ID #REQUIRED Prerequisites IDREFS #IMPLIED Instructors IDREFS    #REQUIRED Enrollment CDATA #IMPLIED>
<!ATTLIST Professor InstrID ID #REQUIRED>
<!ATTLIST Lecturer InstrID ID #REQUIRED>
<!ELEMENT First_Name (#PCDATA)>
<!ELEMENT Middle_Initial (#PCDATA)>
<!ELEMENT Last_Name (#PCDATA)>
<!ELEMENT Description (#PCDATA | Courseref)*>
<!ELEMENT Courseref EMPTY>
<!ATTLIST Courseref Number IDREF #REQUIRED>

Please help me.

Community
  • 1
  • 1
skjindal93
  • 706
  • 1
  • 16
  • 34

3 Answers3

1

[First, a note -- you'll get better results asking questions if you provide a little more evidence that you have done some work on your own: it makes you seem more like someone who could use help and less like someone who doesn't want to do any work themselves, and it helps answerers understand better what they do and don't need to explain. Also, a fuller account of what you've tried and why it doesn't work will almost always include an account of the error messages you're getting, which can be helpful to someone wanting to help you. If you want to get help on Stack Overflow, it's a good idea to read Eric Raymond on how to ask good questions, and do what he says.]

The Department elements in the sample document you provide each begin with exactly one Title element, continue with a variable number of Course elements, and end with a mixture of Professor and Lecturer elements. Which part of this don't you understand how to express? (And what on earth does it have to do with determinism?)

Here are some element declarations that will accept the Department elements in the sample.

<!ELEMENT Department ANY >
<!ELEMENT Department (Title | Course | Professor | Lecturer)* >
<!ELEMENT Department (Title | Course | Professor | Lecturer)+ >
<!ELEMENT Department (Title, Course*, (Professor | Lecturer)* >
<!ELEMENT Department (Title, Course+, (Professor | Lecturer)+ >
<!ELEMENT Department (Title, Course+, (Professor?, Lecturer?)* >
<!ELEMENT Department (Title, Course+, (Professor?, Lecturer?)+ >
<!ELEMENT Department (Title, Course*, 
                     (Professor | Lecturer | Instructor | TA)* >
<!ELEMENT Department (Title, Course+, Professor,
                     (Professor | Lecturer)+ >

Does that help?

C. M. Sperberg-McQueen
  • 24,596
  • 5
  • 38
  • 65
0

What have you tried that didn't work?

You may not be aware that content models can have more than one level of parentheses, for grouping purposes. Something like

(Title, Course+, (Professor | Lecturer)+)

should work for this XML instance, but other instances of Course_catalog XML may reveal other requirements.

arayq2
  • 2,502
  • 17
  • 21
0

Try this

<!ELEMENT Course_Catalog (Department*)>
<!ELEMENT Department (Title, Course*,  (Professor | Lecturer)+)>
<!ATTLIST Department Code CDATA #REQUIRED
                                 Chair IDREF #REQUIRED>
<!ELEMENT Title (#PCDATA)>
<!ELEMENT Professor (First_Name, Middle_Initial?, Last_Name)>
<!ATTLIST Professor InstrID  ID  #REQUIRED>
<!ELEMENT First_Name (#PCDATA)>
<!ELEMENT Last_Name (#PCDATA)>
<!ELEMENT Course (Title, Description?)>
<!ELEMENT Description (#PCDATA | Courseref )*>
<!ELEMENT Courseref EMPTY>
<!ATTLIST Courseref Number IDREF  #REQUIRED>
<!ATTLIST Course Number ID #REQUIRED
                           Prerequisites CDATA #IMPLIED
                           Instructors IDREFS #REQUIRED
                           Enrollment  CDATA #IMPLIED>
<!ELEMENT Instructors (Professor | Lecturer)+>
<!ELEMENT Lecturer (First_Name, Middle_Initial?, Last_Name)>
<!ATTLIST Lecturer InstrID  ID  #REQUIRED>
<!ELEMENT Middle_Initial (#PCDATA)>

Thanks, Bimal

Bimal
  • 1,175
  • 8
  • 16