Search code examples
xmldtd

XML to DTD error: the document type declaration must be well-formed


I'm a beginner to XML, I have to convert the following XML to DTD

<student id="12C042">

    <fName>John</fName>

    <lName>Nelson</lName>

    <plan>

        <courses year="3">

            <course>

                <name> Extensible Markup Language</name>

                <shortName>XML</shortName>

                <record>

                    <grade>30</grade>

                    <date>12-Jan-2017</date>

                </record>

            </course>

            <course>

                <name>Object Oriented Concepts and Unified Modeling Language</name>

                <shortName><![CDATA[OOP & UML]]></shortName>

            </course>

        </courses>

    </plan>

This is the DTD, I obtained after conversion:

 <?xml encoding="UTF-8"?>

<!ELEMENT student (fName,lName,plan)>
<!ATTLIST student
  xmlns CDATA #FIXED ''
  id NMTOKEN #REQUIRED>

<!ELEMENT fName (#PCDATA)>
<!ATTLIST fName
  xmlns CDATA #FIXED ''>

<!ELEMENT lName (#PCDATA)>
<!ATTLIST lName
  xmlns CDATA #FIXED ''>

<!ELEMENT plan (courses)>
<!ATTLIST plan
  xmlns CDATA #FIXED ''>

<!ELEMENT courses (course)+>
<!ATTLIST courses
  xmlns CDATA #FIXED ''
  year CDATA #REQUIRED>

<!ELEMENT course (name,shortName,record?)>
<!ATTLIST course
  xmlns CDATA #FIXED ''>

<!ELEMENT name (#PCDATA)>
<!ATTLIST name
  xmlns CDATA #FIXED ''>

<!ELEMENT shortName (#PCDATA)>
<!ATTLIST shortName
  xmlns CDATA #FIXED ''>

<!ELEMENT record (grade,date)>
<!ATTLIST record
  xmlns CDATA #FIXED ''>

<!ELEMENT grade (#PCDATA)>
<!ATTLIST grade
  xmlns CDATA #FIXED ''>

<!ELEMENT date (#PCDATA)>
<!ATTLIST date
  xmlns CDATA #FIXED ''>

The compiler gives following error:

Fatal error:
Public ID: null
System ID: file:/home/p12947/studentdtd.dtd
Line number: 9
Column number: 2
Message: The markup declarations contained or pointed to by the document type declaration must be well-formed.
Fatal


Solution

  •  <?xml version="1.0" encoding="UTF-8"?>
            <persons>
                      <person>
                            <name>XYZ</name>
                             <age>19</age>
                             <gender>M</gender>
                             <address>
                                 <doorno>4</doorno>
                                 <street>ABC</street>
                                <city>DEL</city>
                                <state>IND</state>
                           </address>
                            <student>
                                <rollno>34</rollno>
                                <standard>12</standard>
                                <section>C</section>
                             </student>
                     </person>
          </persons>