Reputation: 133
I'm trying to write a DTD for an XML file.Here it is : https://prod-c2g.s3.amazonaws.com/db/Winter2013/files/courses-noID.xml
Here's my DTD
<!ELEMENT Course_Catalog (Department*) >
<!ELEMENT Department (Title*, Chair*, Course*) >
<!ATTLIST Department Code CDATA #REQUIRED >
<!ELEMENT Title ANY >
<!ELEMENT Chair (Professor) >
<!ELEMENT Professor (First_Name, Middle_Initial?, Last_Name) >
<!ELEMENT First_Name ANY >
<!ELEMENT Last_Name ANY >
<!ELEMENT Course (Title, Description?, Instructors, Prerequisites?) >
<!ATTLIST Course Number CDATA #REQUIRED Enrollment CDATA #IMPLIED >
<!ELEMENT Description ANY >
<!ELEMENT Instructors (Professor*, Lecturer?) >
<!ELEMENT Lecturer (First_Name, Middle_Initial?, Last_Name) >
<!ELEMENT Middle_Initial ANY >
<!ELEMENT Prerequisites (Prereq*)>
<!ELEMENT Prereq ANY >
Well it looks almost fine but there is a slight error.It says 'validity error : Element Instructors content does not follow the DTD, expecting (Professor* , Lecturer?), got (Lecturer Professor Professor )'.Isn't * means any number of elements?Why is there an error?
Upvotes: 1
Views: 2019
Reputation: 52888
Isn't * means any number of elements?Why is there an error?
Yes, but the ,
is specifying an order. Your model (Professor* , Lecturer?)
means zero or more Professor
followed by zero or one Lecturer
. The XML found an occurrence of one Lecturer
followed by 2 Professor
.
This model could be (Lecturer,Professor+)
, but it depends on what the other Instructors
elements look like. Start with (Lecturer,Professor+)
and "loosen" it as required.
Upvotes: 3
Reputation: 600
You probably should have written your DTD first ... but ...
Why don't you download the trial version of Stylus Studio that includes a DTD generator. http://www.stylusstudio.com/dtd%5Fgenerator.html
Upvotes: 0