XML-文档类型声明包含或指向的标记声明必须格式正确

问题描述

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE  hotels  SYstem "food.dtd">
<breakfast_menu>
 <food>
  <name>Turfle waffles</name>
  <price>$5.95</price>
  <description>This two turfle which has 2 famous product  is with real choco and maple 
   syrup</description>
  <calories>650</calories>
 </food>

 <food>
  <name>StrawBerry Belgian Waffles</name>
  <price>$24.6</price>
  <description>Light Belgian waffles covered with strawberries and whipped cream</description>
  <calories>900</calories>
 </food>

 <food>
  <name>Berry-Berry Belgian Waffles</name>
  <price>$4.78</price>
  <description>Light Belgian waffles covered with an assortment of fresh berries and whipped 
   cream</description>
  <calories>400</calories>
 </food>

 <food>
  <name>Fried Toast</name>
  <price>$7.68</price>
  <description>Thick slices made from our homemade wheat dough bread</description>
  <calories>250</calories>
 </food>

 <food>
  <name>Homestyle Breakfast</name>
  <price>$7.95</price>
  <description>Two eggs,bacon or sausage,toast,and England popular  hash browns</description>
  <calories>1500</calories>
 </food>
</breakfast_menu>

我尝试了以下代码

    <?xml version="1.0" encoding="UTF-8"?>
    <!ELEMENT breakfast_menu (food+)>
    <!ELEMENT food (name,price,description,calories)>
    <!ELEMENT name (#PCDATA)>
    <!ELEMENT price (#PCDATA)>
    <!ELEMENT description (#PCDATA)>
    <!ELEMENT calories (#PCDATA)>
    <breakfast_menu>
     <element>
      <name>Turfle waffles</name>
      <price>$5.95</price>
      <description>This two turfle which has 2 famous product  is with real choco and maple 
       syrup</description>
      <calories>650</calories>
     </element>
    
     <element>
      <name>StrawBerry Belgian Waffles</name>
      <price>$24.6</price>
      <description>Light Belgian waffles covered with strawberries and whipped cream</description>
      <calories>900</calories>
     </element>
    
     <element>
      <name>Berry-Berry Belgian Waffles</name>
      <price>$4.78</price>
      <description>Light Belgian waffles covered with an assortment of fresh berries and whipped 
       cream</description>
      <calories>400</calories>
     </element>
    
     <element>
      <name>Fried Toast</name>
      <price>$7.68</price>
      <description>Thick slices made from our homemade wheat dough bread</description>
      <calories>250</calories>
     </element>
    
     <element>
      <name>Homestyle Breakfast</name>
      <price>$7.95</price>
      <description>Two eggs,and England popular  hash browns</description>
      <calories>1500</calories>
     </element>
    </breakfast_menu>

代码抛出错误: 致命错误: 公开ID:空 系统ID:文件:/home/p10936/food.dtd 行号:8 列数:2 消息:文档类型声明包含或指向的标记声明必须格式正确。 致命的

我需要将XML代码转换为DTD代码。 我是新来的!而且我找不到任何帮助!

解决方法

只需删除XML声明(第一行)和内容即可。从<breakfast_menu>到文件food.dtd的所有内容。 DTD文件应该仅包含标记声明。