格式良好的XML DTD

时间:2014-11-30 14:58:41

标签: xml dtd

我通过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>

1 个答案:

答案 0 :(得分:1)

请注意,您的XML文档 格式正确 ,但 无效 。您可以阅读the difference between well-formed and invalid here

要使您的XML有效:

  1. 更改WEBDESIGNTOPICS的内容模型以反映这一事实 它显然只是topics的列表:

     <!ELEMENT WEBDESIGNTOPICS (topic+)>
    
  2. 更改主题的内容模型以反映它可以包含的内容模型 一个或多个topicnamedescriptionprovided元素。 您必须确定作为样本的必要性和基数 XML不能表明一般性:

    <!ELEMENT topic (topicname,description,provided)>
    
  3. 然后,这个更新的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>