DTD问题:“内容模型不是决定论者”。 [英] A DTD problem: "Content model is not determinist"

查看:79
本文介绍了DTD问题:“内容模型不是决定论者”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!


我一直遇到DTD问题。有了Sun XML验证器

拒绝了一个文件,我把它通过''xmllint'来获取更多信息。


''Xmllint''注意到了DTD本身的问题;

"有效性错误:部分的内容模型不是决定论者:(文本,

(列表,文本)*,列表?)"


这是一个非常简化的DTD版本,证明了这个问题: -

<?xml version =" 1.0" encoding =" iso-8859-1"?>

<!ELEMENT部分(文字,(列表,文字)*,列表?)>

< ;!ELEMENT列表(项目+)>

<!ELEMENT item(text)>

<!ELEMENT text(#PCDATA)*>


section元素是问题行;它应该允许*任何*

序列的交替< text>和< list>以

< text>开头的元素元素。


我的猜测......要么我已经违反了XML的特定规则,要么(因为我怀疑使用这个词来获得
) ''确定主义'')那里有一个基本的歧义

的逻辑。我*不认为这个问题是xmllint中的一个错误,因为

Sun的XML验证器之前已经给出了意想不到的结果(因此我使用了xmllint的
)更多信息)。


(样本文件在本文末尾,如果有任何帮助的话)。


Any反馈将不胜感激。谢谢!


- MS


===================== =============


<!DOCTYPE section SYSTEM" problem.dtd">

< section>

< text> Filler 1< / text>

< list>

< item>< text> Filler 2a< / text>< ; / item>

< item>< text> Filler 2b< / text>< / item>

< / list>

< text>填充3< / text>

< list>

< item>< text>填充器4a< / text>< / item> ;

< item>< text> Filler 4b< / text>< / item>

< / list>

< ; / section>


<?xml version =" 1.0" encoding =" iso-8859-1"?>

<!DOCTYPE section SYSTEM" problem.dtd">

< section>

< text> Filler 1< / text>

< list>

< item>< text> Filler 2a< / text>< ; / item>

< item>< text> Filler 2b< / text>< / item>

< / list>

< text>填充3< / text>

< list>

< item>< text>填充器4a< / text>< / item> ;

< item>< text> Filler 4b< / text>< / item>

< / list>

< ; text> Filler 5< / text>

< / section>

Hi!

I''ve been having problems with a DTD. Having had the Sun XML validator
reject a document, I put it through ''xmllint'' for more information.

''Xmllint'' noted a problem with the DTD itself;
"validity error : Content model of section is not determinist: (text ,
(list , text)* , list?)"

Here''s a very simplified version of the DTD demonstrating the problem:-
<?xml version="1.0" encoding="iso-8859-1"?>
<!ELEMENT section (text, (list, text)*, list?)>
<!ELEMENT list (item+)>
<!ELEMENT item (text)>
<!ELEMENT text (#PCDATA)*>

The section element is the problem line; it should permit *any*
sequence of alternating <text> and <list> elements that start with a
<text> element.

My guess... either I''ve broken a specific rule of XML, or (as I suspect
from the use of the word ''determinist'') there''s a fundamental ambiguity
of logic in there. I *don''t* think the problem is a bug in xmllint, as
Sun''s XML validator had previously given unexpected results (hence my
use of xmllint for more info).

(Sample documents are at the end of this post, if that''s any help).

Any feedback would be appreciated. Thank you!

- MS

==================================

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE section SYSTEM "problem.dtd">
<section>
<text>Filler 1</text>
<list>
<item><text>Filler 2a</text></item>
<item><text>Filler 2b</text></item>
</list>
<text>Filler 3</text>
<list>
<item><text>Filler 4a</text></item>
<item><text>Filler 4b</text></item>
</list>
</section>

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE section SYSTEM "problem.dtd">
<section>
<text>Filler 1</text>
<list>
<item><text>Filler 2a</text></item>
<item><text>Filler 2b</text></item>
</list>
<text>Filler 3</text>
<list>
<item><text>Filler 4a</text></item>
<item><text>Filler 4b</text></item>
</list>
<text>Filler 5</text>
</section>

推荐答案

在文章< ; 11 ********************** @ z14g2000cwz.googlegroups .com>,

Michael Strorm< ms ***** @ yahoo.co.uk>写道:
In article <11**********************@z14g2000cwz.googlegroups .com>,
Michael Strorm <ms*****@yahoo.co.uk> wrote:
" valid error:section的内容模型不是决定论者:( text,
(list,text)*,list?)"
"validity error : Content model of section is not determinist: (text ,
(list , text)* , list?)"




内容模型必须是确定性的,因为在每一点上,

内容模型中只有一个标签与下一个标签相匹配

元素。在您的内容模型中,当有< list>时在< text>之后,

有两种可能性:加星标组中的文本,以及最后的




通常可以重写你的内容模型,以确定它是确定的,但遗憾的是不是这种情况。你的是最简单的不可确定内容模型的一个例子

。 (这与国际象棋游戏模型相同,黑白必须交替使用。)


你只需要做一个不太精确的内容模型,它不会被b $ b检查交替,例如(text | list)*


- Richard



A content model has to be deterministic in the sense that at every point,
there must only be one label in the content model that matches the next
element. In your content model, when there is a <list> after a <text>,
there are two possibilities: the text in the starred group, and the
one at the end.

Usually it is possible to rewrite your content model so that it is
deterministic, but unfortunately not in this case. Yours is an example
of the simplest non-determinizable content model. (It''s the same as
the chess game model where black and white must alternate.)

You''ll just have to make do with a less precise content model that won''t
check the alternation, such as (text|list)*

-- Richard


我感谢你的帮助,我明白你在说什么。


如果你不想进去,我会理解的一个冗长的讨论

关于这一点,但是......为什么这应该是一个问题?是否与

保持XML解析器相当简单?


换句话说;一旦整个<部分>元素已被阅读,那里有
没有歧义。如果< list>那个含糊不清的是最后的元素,

它对应于最终的''列表?''。如果后跟另一个

< text>,则必须是''(list | text)*''中的另一个列表。


出于兴趣,这是DTD的限制还是XML的一般限制?

(稍微使用过DTD,我可以理解为什么他们要替换它们b / b
像XML Schema和Relax NG ... ...


无论如何,谢谢!


- MS

I appreciate your help, and I see what you are saying.

I''ll understand if you don''t want to get in a longwinded discussion
about this, but..... why should this be a problem? Is it to do with
keeping the XML parsers reasonably simple?

Put another way; once the whole <section> element has been read, there
is no ambiguity. If the <list> that was ambiguous is the final element,
it corresponds to the final ''list?''. If it is followed by another
<text>, it must be the other list, in the ''(list | text)*''.

Out of interest, is this a limitation of DTDs or with XML in general?
(Having used DTDs a bit, I can understand why they wanted to replace
them with the likes of XML Schema and Relax NG...)

Anyway, thanks!

- MS


2005年8月18日17:47:43 -0700,Michael Strorm < MS ***** @ yahoo.co.uk>写道:
On 18 Aug 2005 17:47:43 -0700, "Michael Strorm" <ms*****@yahoo.co.uk> wrote:
我感谢你的帮助,我明白你在说什么。

如果你不想进去,我会理解的一个关于这个的长篇讨论,但是.....为什么这应该是一个问题呢?是否与保持XML解析器相当简单有关?


这更像是让他们不能完全陷入困境。在一组规则之间有一个很好的

线,这些规则可以保证拒绝所有非确定性的
模型,但也拒绝许多理论上确定性的规则,以及一组

规则的代码无法编写,可以确定

a模型的确定性,并保证在有限的时间内完成确定。


现在,除此之外,如果你使一个解析器比另一个解析器更聪明,只需处理比保守规范更多的情况,那么解析器将会是

成功处理了第三方解析器可能没有的模型,所以你会用
轻率地使用你的模型来创建一个不能用来与

一些第三方。

另一种方式;一旦整个<部分>元素已被阅读,那里没有歧义。如果< list>那个含糊不清的是最后的元素,
它对应于最终的''列表?''。如果后跟另一个
< text>,它必须是''(list | text)*''中的另一个列表。

出于兴趣,这是一个一般来说DTD或XML的限制是什么?
(稍微使用过DTD,我可以理解为什么他们想用XML Schema和Relax NG替换它们......)
I appreciate your help, and I see what you are saying.

I''ll understand if you don''t want to get in a longwinded discussion
about this, but..... why should this be a problem? Is it to do with
keeping the XML parsers reasonably simple?
It''s more like keeping them from being completely intractible. There''s a fine
line between a set of rules that guarantees to reject all non-deterministic
models, but also rejects many that are theoretically deterministic, and a set
of rule for which code cannot be written that can determine the determinism of
a model and be guaranteed to finish making the determination in finite time.

Now, add to that the fact that if you make one parser smarter than another by
handling just a few more cases than the conservative spec., that parser will
successfully process a model that a 3rd party''s parser might not, so you''ll
blithely use yours to create a model that can''t be used to communicate with
some 3rd parties.
Put another way; once the whole <section> element has been read, there
is no ambiguity. If the <list> that was ambiguous is the final element,
it corresponds to the final ''list?''. If it is followed by another
<text>, it must be the other list, in the ''(list | text)*''.

Out of interest, is this a limitation of DTDs or with XML in general?
(Having used DTDs a bit, I can understand why they wanted to replace
them with the likes of XML Schema and Relax NG...)




在这种情况下,XML Schema无济于事。我不知道RELAX NG。



XML Schema does not help in this case. I don''t know about RELAX NG.


这篇关于DTD问题:“内容模型不是决定论者”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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