我通过w3schools验证器运行我的XML / DTD它告诉我它有很多错误,我做错了什么?我承认自从我使用XML
以来已经有几年了<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
<!DOCTYPE WEBDESIGNTOPICS [
<!ELEMENT WEBDESIGNTOPICS (topic+,topicname+,description+,provided)>
<!ELEMENT topic (#PCDATA)>
<!ELEMENT topicname (#PCDATA)>
<!ELEMENT description (#PCDATA)>
<!ELEMENT provided (#PCDATA)>
]>
<WEBDESIGNTOPICS>
<topic>
<topicname>HTML5</topicname>
<description>HAMILTON</description>
<provided>SALESMAN</provided>
</topic>
<topic>
<topicname>CSS/CSS3</topicname>
<description>SMITH</description>
<provided>CLEANER</provided>
</topic>
<topic>
<topicname>PHP</topicname>
<description>JONES</description>
<provided>MANAGER</provided>
</topic>
<topic>
<topicname>JavaScript</topicname>
<description>JONES</description>
<provided>MANAGER</provided>
</topic>
<topic>
<topicname>jQuery</topicname>
<description>JONES</description>
<provided>MANAGER</provided>
</topic>
</WEBDESIGNTOPICS>
答案 0 :(得分:1)
请注意,您的XML文档 格式正确 ,但 无效 。您可以阅读the difference between well-formed and invalid here。
要使您的XML有效:
更改WEBDESIGNTOPICS
的内容模型以反映这一事实
它显然只是topics
的列表:
<!ELEMENT WEBDESIGNTOPICS (topic+)>
更改主题的内容模型以反映它可以包含的内容模型
一个或多个topicname
,description
和provided
元素。
您必须确定作为样本的必要性和基数
XML不能表明一般性:
<!ELEMENT topic (topicname,description,provided)>
然后,这个更新的XML文档将是有效的:
<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
<!DOCTYPE WEBDESIGNTOPICS [
<!ELEMENT WEBDESIGNTOPICS (topic+)>
<!ELEMENT topic (topicname,description,provided)>
<!ELEMENT topicname (#PCDATA)>
<!ELEMENT description (#PCDATA)>
<!ELEMENT provided (#PCDATA)>
]>
<WEBDESIGNTOPICS>
<topic>
<topicname>HTML5</topicname>
<description>HAMILTON</description>
<provided>SALESMAN</provided>
</topic>
<topic>
<topicname>CSS/CSS3</topicname>
<description>SMITH</description>
<provided>CLEANER</provided>
</topic>
<topic>
<topicname>PHP</topicname>
<description>JONES</description>
<provided>MANAGER</provided>
</topic>
<topic>
<topicname>JavaScript</topicname>
<description>JONES</description>
<provided>MANAGER</provided>
</topic>
<topic>
<topicname>jQuery</topicname>
<description>JONES</description>
<provided>MANAGER</provided>
</topic>
</WEBDESIGNTOPICS>