验证XML和DTD时出错 [英] Errors when validating XML and DTD

查看:76
本文介绍了验证XML和DTD时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理XML文件,但遇到问题。

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

这是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!

推荐答案


这是我到目前为止所做的(验证没问题)

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

该部分的验证不正确。关于 itemizedlist orderedlist 不完整的错误应该会出现。它们至少需要1个 listitem (听起来您正在尝试添加)。

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>

我将空的 para 元素添加到 listitem ,因为至少需要以下一项: para 节目列表项目清单订单清单

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

这篇关于验证XML和DTD时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆