Reputation: 636
I'm supposed to be writing a DTD for an xml document but there is one particular section that is throwing me for a loop. In the EnrolledIn element there is character data and then course elements. I've tried to validate with the DTD below but I keep getting the error
"ERROR: Element EnrolledIn content does not follow the DTD, expecting (CDATA , Course+), got (CDATA Course Course Course Course )
ERROR: Element EnrolledIn content does not follow the DTD, expecting (CDATA , Course+), got (CDATA Course )".
I've tried using * and + after course but with no success. I'm using Notepad++ xml tools to validate.
<!DOCTYPE Students [
<!ELEMENT Students (Student*)>
<!ELEMENT Student (LastName, MiddleInitial?, FirstName, EnrolledIn?)>
<!ELEMENT LastName (#PCDATA)>
<!ELEMENT FirstName (#PCDATA)>
<!ELEMENT MiddleInitial (#PCDATA)>
<!ELEMENT EnrolledIn (CDATA, Course+)>
<!ELEMENT Course (#PCDATA)>
]>
<Students>
<Student>
<LastName> Doe </LastName>
<MiddleInitial>K.</MiddleInitial>
<FirstName>John</FirstName>
<EnrolledIn>
Courses enrolled in:
<Course>
TCSS 445 – Database Systems Design
</Course>
<Course>
TCSS 422 – Operating Systems
</Course>
<Course>
TCSS 422 – Operating Systems
</Course>
<Course>
TBUS 301 Quantitative Analysis for Business
</Course>
</EnrolledIn>
</Student>
<Student>
<LastName> Smith </LastName>
<FirstName>Amy</FirstName>
<EnrolledIn>
Courses enrolled in:
<Course>
TBUS 100 Introduction to Business
</Course>
</EnrolledIn>
</Student>
<Student>
<LastName> Doe </LastName>
<MiddleInitial> L. </MiddleInitial>
<FirstName>Jane</FirstName>
</Student>
</Students>
Upvotes: 2
Views: 704
Reputation: 52858
That's called a mixed content model and there is only one way to write it. (See here: http://www.w3.org/TR/REC-xml/#sec-mixed-content)
<!ELEMENT EnrolledIn (#PCDATA|Course)*>
You aren't going to be able to restrict the order of the text (#PCDATA) and the Course
elements. With mixed content it's always zero or more of everything in the model (in any order).
Upvotes: 1