我不明白为什么这个来自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)>
]>
答案 0 :(得分:1)
W3C XML/HTML Markup Validation服务只验证文档,而不是DTD本身。将有效文档附加到DTD以检查DTD和文档like this:
<?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>