Errors when validating XML and DTD

巧了我就是萌 提交于 2020-01-17 04:15:08

问题


I'm working on a XML file and I'm having issues with it.

Here's the DTD :

<!ELEMENT book (bookinfo,chapter*)>
<!ELEMENT chapter (title,section*)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT bookinfo (title,author,copyright)>
<!ELEMENT author (firstname,surname)>
<!ELEMENT copyright (year,holder)>
<!ENTITY % divers "para|programlisting|itemizedlist|orderedlist">
<!ELEMENT section (title,(%divers;)+)>
<!ELEMENT para (#PCDATA)>
<!ELEMENT programlisting (#PCDATA)>
<!ELEMENT holder (#PCDATA)>
<!ELEMENT surname (#PCDATA)>
<!ELEMENT firstname (#PCDATA)>
<!ELEMENT year (#PCDATA)>
<!ELEMENT itemizedlist (listitem+)>
<!ELEMENT orderedlist (listitem+)>
<!ELEMENT listitem (%divers;)+>

Here's what I've done so far (Validation is okay with this part)

<?xml version="1.0" encoding='ISO-8859-1' standalone="no"?>
<!DOCTYPE book SYSTEM "simpledocbook.dtd">
<?xml-stylesheet href="docbook.xml" type="application/xml"?>
<book>
<bookinfo>
<title></title>
<author>
<firstname></firstname>
<surname></surname>
</author>
<copyright>
<year></year>
<holder></holder>
</copyright>
</bookinfo>
<chapter>
<title></title>
<section>
<title></title>
<para></para>
<programlisting></programlisting>
</section>
</chapter>
<chapter>
<title></title>
<section>
<title></title>
<para></para>
<programlisting></programlisting>
<itemizedlist></itemizedlist>
<orderedlist></orderedlist>
</section>
</chapter>
</book>

My problem occurs when I try to add itemlist, I don't know where I should put it in the code? Everything I try to put it somewhere I get errors.

Can you guys help me finding why it doesn't work? Thanks a lot!


回答1:


Here's what I've done so far (Validation is okay with this part)

Validation should not be ok with that part. You should be getting errors about itemizedlist and orderedlist being incomplete. They require at least 1 listitem (which it sounds like you're trying to add).

Here's a modified version that is valid:

<!DOCTYPE book SYSTEM "simpledocbook.dtd">
<?xml-stylesheet href="docbook.xml" type="application/xml"?>
<book>
    <bookinfo>
        <title></title>
        <author>
            <firstname></firstname>
            <surname></surname>
        </author>
        <copyright>
            <year></year>
            <holder></holder>
        </copyright>
    </bookinfo>
    <chapter>
        <title></title>
        <section>
            <title></title>
            <para></para>
            <programlisting></programlisting>
        </section>
    </chapter>
    <chapter>
        <title></title>
        <section>
            <title></title>
            <para></para>
            <programlisting></programlisting>
            <itemizedlist>
                <listitem>
                    <para/>
                </listitem>
            </itemizedlist>
            <orderedlist>
                <listitem>
                    <para/>
                </listitem>
            </orderedlist>
        </section>
    </chapter>
</book>

I added empty para elements to the listitem's because at least 1 of the following are required: para, programlisting, itemizedlist or orderedlist



来源:https://stackoverflow.com/questions/28994708/errors-when-validating-xml-and-dtd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!