0

我不明白为什么 XML 文档中的这个 DTD 不会验证。它给我的错误是最后一行的“没有文档元素”。这很愚蠢,因为我可以删除除两行之外的所有代码,它仍然给我错误。我是 XML 的初学者,所以也许有更多经验的人来看看我?

<?xml version = "1.0" encoding="utf-8" standalone="yes"?>
<!DOCTYPE events [
<!ELEMENT events (event)+>
<!ELEMENT event (itenerary, description, icon?, leader+, coordinator+, maxpart, registeredpart, carpool?, difficulty, cost?, destination)>
<!ELEMENT itenerary (startdate, enddate, departuretime, location)>
<!ELEMENT contact (name,phone+)>
<!ELEMENT name (firstname, lastname)>
<!ELEMENT startdate (year, month, day)>
<!ELEMENT enddate (year, month, day)>
<!ELEMENT year (#PCDATA)>
<!ELEMENT month (#PCDATA)>
<!ELEMENT day (#PCDATA)>
<!ELEMENT departuretime (hours,minutes)>
<!ELEMENT hours (#PCDATA)>
<!ELEMENT minutes (#PCDATA)>
<!ELEMENT location (street,city)>
<!ELEMENT street (#PCDATA)>
<!ELEMENT city (#PCDATA)>
<!ELEMENT description (#PCDATA)>
<!ELEMENT icon (#PCDATA)>
<!ELEMENT leader (contact+)>
<!ELEMENT firstname (#PCDATA)>
<!ELEMENT lastname (#PCDATA)>
<!ELEMENT phone (landline?, cell?)> 
<!ELEMENT coordinator (contact)>
<!ELEMENT landline (#PCDATA)>
<!ELEMENT cell (#PCDATA)>
<!ELEMENT maxpart (#PCDATA)>
<!ELEMENT registeredpart (#PCDATA)>
<!ELEMENT carpool (#PCDATA)>
<!ELEMENT difficulty (#PCDATA)>
<!ELEMENT cost (#PCDATA)>
<!ELEMENT destination (location)> 
]>
4

1 回答 1

1

W3C XML/HTML 标记验证服务只验证文档,而不是 DTD 本身。将有效文档附加到您的 DTD 以检查 DTD 和文档,如下所示

<?xml version = "1.0" encoding="utf-8" standalone="yes"?>
<!DOCTYPE events [
<!ELEMENT events (event)+>
<!ELEMENT event (itenerary, description, icon?, leader+, coordinator+, maxpart, registeredpart, carpool?, difficulty, cost?, destination)>
<!ELEMENT itenerary (startdate, enddate, departuretime, location)>
<!ELEMENT contact (name,phone+)>
<!ELEMENT name (firstname, lastname)>
<!ELEMENT startdate (year, month, day)>
<!ELEMENT enddate (year, month, day)>
<!ELEMENT year (#PCDATA)>
<!ELEMENT month (#PCDATA)>
<!ELEMENT day (#PCDATA)>
<!ELEMENT departuretime (hours,minutes)>
<!ELEMENT hours (#PCDATA)>
<!ELEMENT minutes (#PCDATA)>
<!ELEMENT location (street,city)>
<!ELEMENT street (#PCDATA)>
<!ELEMENT city (#PCDATA)>
<!ELEMENT description (#PCDATA)>
<!ELEMENT icon (#PCDATA)>
<!ELEMENT leader (contact+)>
<!ELEMENT firstname (#PCDATA)>
<!ELEMENT lastname (#PCDATA)>
<!ELEMENT phone (landline?, cell?)> 
<!ELEMENT coordinator (contact)>
<!ELEMENT landline (#PCDATA)>
<!ELEMENT cell (#PCDATA)>
<!ELEMENT maxpart (#PCDATA)>
<!ELEMENT registeredpart (#PCDATA)>
<!ELEMENT carpool (#PCDATA)>
<!ELEMENT difficulty (#PCDATA)>
<!ELEMENT cost (#PCDATA)>
<!ELEMENT destination (location)> 
]>
<events>
  <event>
    <itenerary><!-- Did you mean itinerary ? -->
      <startdate><year>2013</year><month>1</month><day>1</day></startdate>
      <enddate><year>2013</year><month>1</month><day>2</day></enddate>
      <departuretime><hours>12</hours><minutes>01</minutes></departuretime>
      <location>
        <street>Kölner Straße</street>
        <city>Düsseldorf</city>
      </location>
    </itenerary>
    <description>A short trip</description>
    <leader>
      <contact><name><firstname>John</firstname><lastname>Smith</lastname></name><phone/></contact>
    </leader>
    <coordinator>
      <contact><name><firstname>Jane</firstname><lastname>Smith</lastname></name><phone/></contact>
    </coordinator>
    <maxpart>??</maxpart>
    <registeredpart>???</registeredpart>
    <difficulty>easy</difficulty>
    <destination>
      <location>
        <street>Aachener Straße</street>
        <city>Düsseldorf</city>
      </location>
    </destination>
  </event>
</events>
于 2013-01-27T19:51:04.780 回答