【问题标题】:Trying to validate XML against DTD尝试根据 DTD 验证 XML
【发布时间】:2016-05-10 09:03:03
【问题描述】:

我正在尝试生成有效的 xdxf 文档 (here's the DTD)。除了一个错误,我已经设法解决了所有错误,但我不知道出了什么问题。

相关部分是

...
<def>
    <def>
        <gr>n. s.</gr>
        <deftext>
            <tr>pronunciation</tr>
            <dtrn>Meaning</dtrn>
        </deftext>
        <co>Inflected forms</co>
        <ex>
            <ex_orig>Examples</ex_orig>
        </ex>
    </def>
    <def>
        <gr>n. s.</gr>
        <deftext>
            <tr>pronunciation</tr>
            <dtrn>Another meaning</dtrn>
        </deftext>
        <co>Inflected forms</co>
        <ex>
            <ex_orig>Examples</ex_orig>
        </ex>
    </def>
</def>
...

我得到的错误(两次,所以我猜是内部def,而不是外部)是:

元素类型“def”的内容必须匹配 "(gr?,ex*,co*,sr?,etm?,categ*,(def+|deftext))"。

that's none or one gr (ok), none or many ex (ok), none or many co (ok), none或一个 sretm(无)、无或多个 categ(正常)以及一个或多个 def或者恰好是一个 deftext(外部和内部 def 都可以)。我的理解是正确的还是我忽略了什么?

【问题讨论】:

    标签: xml validation dtd


    【解决方案1】:

    是的,你说得对:

    没有或只有一个 gr (ok), none 或 many ex (ok), none 或 many co (ok), none 或 one sr, etm (none), none 或 many categ (ok) 以及一个或多个def 或恰好一个 deftext(外部和内部 def 都可以)。我的理解是正确的还是我忽略了什么?

    但是每次你写一个逗号时,它的意思是“然后”——顺序必须遵守。

    因此,您的文档在此 DTD 方面不正确,原因如下:

    <def>
        <gr>n. s.</gr>
        <deftext>
            <tr>pronunciation</tr>
            <dtrn>Another meaning</dtrn>
        </deftext>
        <co>Inflected forms</co>
        <ex>
            <ex_orig>Examples</ex_orig>
        </ex>
    </def>
    

    元素&lt;co&gt;&lt;ex&gt;不允许出现在&lt;deftext&gt;之后。

    修正后的版本是:

    <def>
        <gr>n. s.</gr>
        <ex>
            <ex_orig>Examples</ex_orig>
        </ex>
        <co>Inflected forms</co>
        <deftext>
            <tr>pronunciation</tr>
            <dtrn>Another meaning</dtrn>
        </deftext>
    </def>
    

    首先是&lt;gr&gt;,然后是&lt;ex&gt;,最后是&lt;co&gt;&lt;deftext&gt;

    【讨论】:

    • 这正是问题所在。非常感谢!
    猜你喜欢
    • 2012-05-05
    • 2015-12-24
    • 1970-01-01
    • 2014-03-17
    • 2010-12-12
    • 1970-01-01
    • 2010-11-22
    • 2019-10-25
    • 2018-07-30
    相关资源
    最近更新 更多