XML和DTD:元素类型的内容必须匹配 [英] XML and DTD: The content of element type must match

查看:66
本文介绍了XML和DTD:元素类型的内容必须匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此刻我正在学习XML,并且正在为第一个DTD扩展而苦苦挣扎.

I'm learning XML at the moment and I'm struggling with the first DTD extension.

我的DTD:

<!ELEMENT  biblio (livre*) >

<!ELEMENT  livre (achat , auteurs, titre ) >
<!ATTLIST livre langue CDATA  #IMPLIED
         ref  CDATA  #IMPLIED>



<!ELEMENT  achat EMPTY >
<!ATTLIST achat  date CDATA #IMPLIED
        lieu CDATA #IMPLIED>


<!ELEMENT  titre (#PCDATA)>
<!ATTLIST titre genre CDATA #IMPLIED
        type NMTOKEN #IMPLIED>



<!ELEMENT  auteurs (auteur+) >


<!ELEMENT  auteur ( nom?, prenom? ,sexe?) >
<!ELEMENT nom (#PCDATA)>
<!ELEMENT prenom (#PCDATA)>
<!ELEMENT sexe (#PCDATA)>

如果我启动了解析器,它似乎是:

If I launched the parser,it seems :

元素类型"livre"的内容必须匹配(achat,auteus,titre)

The content of element type "livre" must match (achat , auteus ,titre )

我的XML:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE biblio SYSTEM  "Dtdbiblio.dtd">



<biblio>
    <livre langue="francais" ref="1684561564">
        <achat date="11/11/1993" lieu="london"/>
        <titre genre="G" type="politique">      Tiiiiiiiiiiiiiiiiiiiiiiiiitre </titre>
        <auteurs>
            <auteur>
                <nom>x</nom>
                <prenom>x</prenom>
                <sexe>H</sexe>
            </auteur>
        </auteurs>
    </livre>

</biblio>

如何解决此问题?

推荐答案

(achat,auteurs,titre)中的逗号()指定元素的顺序必须出现.(有关详细信息,请参见此处.)

The commas (,) in (achat , auteurs, titre ) specify the order that the elements must appear. (See here for more detail.)

所以(achat,auteurs,titre)表示恰好一个 achat ,然后恰好是一个 auteurs ,然后是一个 titre .

So (achat , auteurs, titre ) means exactly one achat followed by exactly one auteurs followed by exaclty one titre.

您只需要在XML实例中更改 titre auteurs ...的顺序:

You just need to change the order of titre and auteurs... either in the XML instance:

<biblio>
    <livre langue="francais" ref="1684561564">
        <achat date="11/11/1993" lieu="london"/>
        <auteurs>
            <auteur>
                <nom>x</nom>
                <prenom>x</prenom>
                <sexe>H</sexe>
            </auteur>
        </auteurs>
        <titre genre="G" type="politique">      Tiiiiiiiiiiiiiiiiiiiiiiiiitre </titre>
    </livre>

</biblio>

或在DTD中:

<!ELEMENT  livre (achat, titre, auteurs) >

这篇关于XML和DTD:元素类型的内容必须匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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