0

我正在为这里给出的 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>

请帮我。

4

3 回答 3

1

[首先,请注意——如果你提供更多证据证明你自己完成了一些工作,你会得到更好的提问结果:这让你看起来更像是一个可以使用帮助的人,而不是像一个不需要帮助的人'不想自己做任何工作,它可以帮助回答者更好地理解他们所做的并且不需要解释。此外,更全面地说明您尝试过的方法以及它为什么不起作用的原因几乎总是会包含您收到的错误消息的说明,这对想要帮助您的人会有所帮助。如果您想获得有关 Stack Overflow 的帮助,最好阅读Eric Raymond 了解如何提出好的问题,并按照他说的去做。]

您提供的示例文档中的每个部门元素都以一个 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)+ >

这有帮助吗?

于 2012-12-12T17:06:53.020 回答
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)>

谢谢, 比马尔

于 2013-01-27T04:29:47.267 回答
0

你试过什么没用?

您可能不知道内容模型可以有多个级别的括号,用于分组目的。就像是

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

应该适用于此 XML 实例,但 Course_catalog XML 的其他实例可能会揭示其他要求。

于 2012-12-31T02:26:38.350 回答