DTD和XML不匹配?

时间:2014-06-04 01:53:52

标签: xml validation dtd declare

我正在尝试使我的DTD和XML完美匹配,并使用验证器来检查我的XML和DTD文件是否都匹配。当我运行验证器时,我收到了一个错误,我似乎无法理解它,我多次检查了我的XML和DTD。

错误是:

Error Code: -1072898028
Error Reason: Element content is invalid according to the DTD/Schema. 
Error Line: 46 

我的XML文件:

    <?xml version="1.0"?>
<!DOCTYPE wcms_ontology SYSTEM "wcms_ontology.dtd">
<wcms_ontology>
        <wcms>
            <name>Joomla!</name>
            <homepage>http://www.joomla.org/</homepage>
            <version>2.5.4</version>
            <versiondate>5/2/2012</versiondate>
            <license>Open Source</license>
            <cost>Free</cost>
            <type>General Purpose</type>
            <system_requirements>
                <server_env>CGIM</server_env>
                <operating_system>Any</operating_system>
                <programming_language>PHP</programming_language>
            </system_requirements>
            <security>
            <captcha>Add-on</captcha>
            <login_history>Yes</login_history>
            <session_management>Yes</session_management>
            </security>
            <features>
            <commercial_support>Yes</commercial_support>
            <drag_and_drop>No</drag_and_drop>
            <load_balancing>Yes</load_balancing>
            <page_caching>Yes</page_caching>
            </features>
        </wcms>
        <wcms>
            <name>WordPress</name>
            <homepage>http://www.wordpress.org/</homepage>
            <version>3.3.2</version>
            <versiondate>5/29/2012</versiondate>
            <license>Open Source</license>
            <cost>Free</cost>
            <type>General Purpose</type>
            <system_requirements>
                <server_env>None</server_env>
                <operating_system>Any</operating_system>
                <programming_language>PHP</programming_language>
            </system_requirements>
            <security>
            <captcha>Add-on</captcha>
            <login_history>Add-on</login_history>
            <session_management>Add-on</session_management>
            <features>
            <commercial_support>Yes</commercial_support>
            <drag_and_drop>Yes</drag_and_drop>
            <load_balancing>Yes</load_balancing>
            <page_caching>Add-on</page_caching>
            </features>
        </wcms>
        <wcms>
            <name>Alfresco</name>
            <homepage>http://www.alfresco.com/products/</homepage>
            <version>Enterprise + Community</version>
            <versiondate>2/20/2008</versiondate>
            <license>Open Source</license>
            <cost>$15000/year</cost>
            <type>Document Management</type>
            <system_requirements>
                <server_env>J2EE</server_env>
                <operating_system>Any</operating_system>
                <programming_language>Java</programming_language>
            </system_requirements>
            <security>
            <captcha>No</captcha>
            <login_history>Yes</login_history>
            <session_management>Limited</session_management>
            <features>
            <commercial_support>Yes</commercial_support>
            <drag_and_drop>Limited</drag_and_drop>
            <load_balancing>Yes</load_balancing>
            <page_caching>Limited</page_caching>
            </features>
        </wcms>
                <wcms>
            <name>Kentico CMS for ASP.NET</name>
            <homepage>http://www.kentico.com</homepage>
            <version>7</version>
            <versiondate>11/30/2012</versiondate>
            <license>Closed Source</license>
            <cost>$2000</cost>
            <type>Document Management</type>
            <system_requirements>
                <server_env>IIS/.Net</server_env>
                <operating_system>Windows Only</operating_system>
                <programming_language>C#</programming_language>
            </system_requirements>
            <security>
            <captcha>Yes</captcha>
            <login_history>Yes</login_history>
            <session_management>Yes</session_management>
            <features>
            <commercial_support>Yes</commercial_support>
            <drag_and_drop>Yes</drag_and_drop>
            <load_balancing>Yes</load_balancing>
            <page_caching>Yes</page_caching>
            </features>
        </wcms>
            <wcms>
            <name>TYPO3 Enterprise CMS</name>
            <homepage>http://www.typo3.org</homepage>
            <version>6.1</version>
            <versiondate>2/03/2014</versiondate>
            <license>Open Source</license>
            <cost>Free</cost>
            <type>Enterprise</type>
            <system_requirements>
                <server_env>Apache</server_env>
                <operating_system>Any</operating_system>
                <programming_language>PHP</programming_language>
            </system_requirements>
            <security>
            <captcha>Add-on</captcha>
            <login_history>Yes</login_history>
            <session_management>Yes</session_management>
            <features>
            <commercial_support>Yes</commercial_support>
            <drag_and_drop>Add-on</drag_and_drop>
            <load_balancing>Yes</load_balancing>
            <page_caching>Yes</page_caching>
            </features>
        </wcms> 
</wcms_ontology>

我的DTD文件:

<!ELEMENT wcms_ontology (wcms+)>
<!ELEMENT wcms (name, homepage, version, versiondate, license, cost, type, system_requirements, security, features)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT homepage (#PCDATA)>
<!ELEMENT version (#PCDATA)>
<!ELEMENT versiondate (#PCDATA)>
<!ELEMENT license (#PCDATA)>
<!ELEMENT cost (#PCDATA)>
<!ELEMENT type (#PCDATA)>
<!ELEMENT system_requirements (server_env, operating_system, programming_language)>
<!ELEMENT server_env (#PCDATA)>
<!ELEMENT operating_system (#PCDATA)>
<!ELEMENT programming_language (#PCDATA)>
<!ELEMENT security (captcha, login_history, session_management)>
<!ELEMENT captcha (#PCDATA)>
<!ELEMENT login_history (#PCDATA)>
<!ELEMENT session_management (#PCDATA)>
<!ELEMENT features (commercial_support, drag_and_drop, load_balancing, page_caching)>
<!ELEMENT commercial_support (#PCDATA)>
<!ELEMENT drag_and_drop (#PCDATA)>
<!ELEMENT load_balancing (#PCDATA)>
<!ELEMENT page_caching (#PCDATA)>

由于stackoverflow没有对行进行编号,因此我将提供第46行的屏幕截图:

enter image description here

先谢谢你们!

1 个答案:

答案 0 :(得分:4)

您的XML格式不正确。 <security>元素未在</security>元素之前的<features>结束标记处关闭。

Xerces错误说明:

  

意外元素&#34;功能&#34;。父元素类型的内容   必须匹配&#34;(captcha,login_history,session_management)&#34;

验证错误告诉您<features>元素不应该是<security>的子元素。

如果删除DTD关联,则会看到XML解析错误:

  

元素类型&#34;安全性&#34;必须由匹配的结束标记终止   "</security>"

关闭<security>元素后,它将验证DTD并成为格式良好的XML文档。