S.Sakthybaalan
S.Sakthybaalan

Reputation: 519

The DTD for the following XML gives error

At a school, there are many classes and the following elements are identified.

I created the XML and the DTD using VS 2008. But there is an error in the first line of DTD.

<!DOCTYPE school [
  <!ELEMENT school (principal|ClassTeacher)*>
  <!ELEMENT principal (name,age,address)>
  <!ELEMENT name    (#PCDATA)>
  <!ELEMENT age     (#PCDATA)>
  <!ELEMENT address  (#PCDATA)>
  <!ELEMENT ClassTeacher (cno,td*,nos)>
  <!ELEMENT cno   (#PCDATA)>
  <!ELEMENT td (name,dob)>
  <!ELEMENT name (#PCDATA)>
  <!ELEMENT dob (#PCDATA)>
  <!ELEMENT nos (#PCDATA)>
]>

<school>
  <principal>
    <name>sdasd</name>
    <age>456</age>
    <address>jhkh</address>
  </principal>

  <ClassTeacher>
    <cno>456</cno>
    <td>
      <name>gyj</name>
      <dob>fgd</dob>
    </td>
    <nos>45</nos>
  </ClassTeacher>
</school>

The DTD and XML with error in 1st line

Upvotes: 1

Views: 802

Answers (1)

Jim Garrison
Jim Garrison

Reputation: 86774

Main Problem

The primary issue is that you declare name twice. Remove one of the declarations to fix the immediate error.

Additional Problem

<!ELEMENT school (principal|ClassTeacher)*>

This is a "choice list" of an "element content" declaration, which means school can have either multiple principal or multiple ClassTeacher children but not both. See Element Type Declarations.

Try

<!ELEMENT school (principal, ClassTeacher*)>

This will require that principal is the first element, followed by any number (including zero) of ClassTeacher elements.

Upvotes: 1

Related Questions