RoarG
RoarG

Reputation: 823

What is the right formatting of DTD when an Element can both contain PCDATA and an other ELEMENT

I am provided a XML file and I am suppose to write DTD for the data set.

This is a snippet of the part I am struggling with.

<Course Number="CS124" Prerequisites="CS107 CS109" Instructors="DJ" Enrollment="60">
  <Title>From Languages to Information</Title>
  <Description>
    Natural language processing. Cross-listed as
    <Courseref Number="LING180"/>
    . 
    </Description>
</Course>
<Course Number="CS143" Prerequisites="CS107" Instructors="AA" Enrollment="90">
  <Title>Compilers</Title>
  <Description>
    Principles and practices for design and implementation of compilers and interpreters.
  </Description>
</Course>

What is the correct way to make the DTD fit the XML, when there is PCDATA in the element, but also optionally a other ELEMENT? (See ELEMENT Description)

I thought something like this would work:

<!ELEMENT Description ((#PCDATA | Courseref)*)>

But then I get a parse error:

ContentDecl : Name or '(' expected

What is the correct way to write out the DTD for this this XML to be valid?

Upvotes: 0

Views: 598

Answers (2)

bhv
bhv

Reputation: 5388

<!ELEMENT Courseref EMPTY>
<!ATTLIST Courseref Number CDATA #IMPLIED>

Upvotes: 0

Remy Lebeau
Remy Lebeau

Reputation: 597941

You have too many parentheses:

<!ELEMENT Description (#PCDATA | Courseref)*>

Upvotes: 1

Related Questions