我正在为这里给出的XML编写DTD。 http://s3.amazonaws.com/spark-public/db/docs/courses-ID.xml
我无法弄清楚如何编写部门元素。 这是我的DTD代码。
<!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>
请帮帮我。
答案 0 :(得分:1)
[首先,请注意 - 如果您提供更多证据表明您已经自己完成了一些工作,那么您会得到更好的结果提出问题:它使您看起来更像是可以使用帮助的人不像那些不想自己做任何工作的人,它有助于回答者更好地理解他们做什么,不需要解释什么。此外,更全面地了解您尝试过的内容以及为什么它不起作用几乎总是包含您正在获取的错误消息的帐户,这对想要帮助您的人有帮助。如果您想获得Stack Overflow的帮助,最好阅读Eric Raymond on how to ask good questions,做他说的话。]
您提供的示例文档中的Department元素每个都以一个Title元素开头,继续使用可变数量的Course元素,最后混合使用Professor和Lecturer元素。这部分内容你不明白如何表达? (它究竟与决定论有什么关系?)
以下是一些元素声明,它们将接受样本中的Department元素。
<!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)+ >
这有帮助吗?
答案 1 :(得分:0)
你尝试了哪些不起作用?
您可能不知道内容模型可以有多个括号级别,以便进行分组。像
这样的东西(Title, Course+, (Professor | Lecturer)+)
应该适用于此XML实例,但Course_catalog XML的其他实例可能会显示其他要求。
答案 2 :(得分:0)
试试这个
<!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)>
谢谢, 比马尔