XML to DTD error: the document type declaration must be well-formed
XML to DTD error: the document type declaration must be well-formed
我是 XML 的初学者,我必须将以下 XML 转换为 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>
这是我转换后得到的DTD:
<?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 ''>
编译器给出以下错误:
致命错误:
Public ID: 空
系统ID:文件:/home/p12947/studentdtd.dtd
行号:9
列号:2
消息:文档类型包含或指向的标记声明
声明必须格式正确。
致命
尝试用 'student' 元素包围您的元素
根据您的 dtd 的有效文档可能如下所示
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE student SYSTEM "student.dtd">
<student id="1">
<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>
</student>
<?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>
我是 XML 的初学者,我必须将以下 XML 转换为 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>
这是我转换后得到的DTD:
<?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 ''>
编译器给出以下错误:
致命错误:
Public ID: 空
系统ID:文件:/home/p12947/studentdtd.dtd
行号:9
列号:2
消息:文档类型包含或指向的标记声明
声明必须格式正确。
致命
尝试用 'student' 元素包围您的元素
根据您的 dtd 的有效文档可能如下所示
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE student SYSTEM "student.dtd">
<student id="1">
<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>
</student>
<?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>