XML DTD's ID and IDREF pointers

6.5k Views Asked by At

I am getting an error that i cant seem to find much documentation on.

this is a snippet of the XML.

<Department Code="LING" Chair="BL">
  <Title>Linguistics</Title>
  <Course Number="LING180" Prerequisites="CS107 CS109" Instructors="DJ" Enrollment="60">
    <Title>From Languages to Information</Title>
    <Description>
      Natural language processing. Cross-listed as
      <Courseref Number="CS124"/>
    </Description>
  </Course>
  <Lecturer InstrID="DJ">
    <First_Name>Dan</First_Name>
    <Middle_Init>D.</Middle_Init>
    <Last_Name>Jurafsky</Last_Name>
  </Lecturer>
  <Professor InstrID="BL">
    <First_Name>Beth</First_Name>
    <Last_Name>Levin</Last_Name>
  </Professor>
  <Lecturer InstrID="FZ">
    <First_Name>Frank</First_Name>
    <Last_Name>Zoidberg</Last_Name>
  </Lecturer>
</Department>

and here is my DTD

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

the error that i am getting two errors that have to do with each other the first is

 parser error : xmlParseElementDecl: 'EMPTY', 'ANY' or '(' expected

and the next

 parser error : Content error in the external subset

which are a little vague but i think it has to do with the ID's and IDREFS. as you can see that lecturers and professors both have the same ID pointer reference . the Department attribute Chair and Course attribute Instructors both point to the InstrID. and the Course ELEMENT both references to other Courses through Prerequisites and are referenced to via Courseref with in the Description . as you can see there is a lot being passed around. even though i know through DTD's you cant really restrict what ID is being refferenced as long as there is something there.

but i cant figure out this error am i placing them in a wrong order or are my ID-IDREFS wrong?? any help would be great

2

There are 2 best solutions below

2
On BEST ANSWER
<!ELEMENT Courseref Course IDREF #REQUIRED> 

This should be an ATTLIST and not an ELEMENT

1
On

im doing the same exercise, and finally I got to finish.. I can see a mistake at single view, this is:

 Department (Title, Course+, Professor+, Lecturer?)

I made it this way:

Department (Title,Course*,(Professor|Lecturer)*)

because you can have: A title(1), A course(0..n), Professor or lecturer (0..n alternately)