Att值中的外部实体:为什么被禁止? [英] External Entity in Att Value: Why Forbidden?

查看:98
本文介绍了Att值中的外部实体:为什么被禁止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

有人可以告诉我为什么XML规范声明禁止使用外部实体的属性

值?或者指向

相应的文件?或者更好的是,也许你知道一件作品

左右?


通常强大的外部有点令人沮丧

实体是以这种方式限制的。


示例(myextent.txt只包含一个没有CR的单词):

--------- ----------------------------------------

< !DOCTYPE mydoc [

<!ENTITY myextent SYSTEM&.; / myextent.txt">

]>

< mydoc> ;

< atag name =" fred" value ="& myextent;" />

< / mydoc>

---------------- ---------------------------------


错误:

--------------------------------------------- ----

无法在

属性值中引用外部常规解析实体''myextent''。处理资源时出错...

第6行,第44位

----------------------------- --------------------


感谢您的帮助,

Douglas

解决方案

执行***** ****** @yahoo.com.au (Douglas Reith)写道:

你好,
有人可以告诉我为什么XML规范声明禁止使用外部实体的属性值?或者指向
相应的文件?或者更好的是,或许你知道一件作品吗?

通常强大的外部实体以这种方式受限制有点令人沮丧。

示例(myextent.txt只包含一个没有CR的单词):
----------------------------- --------------------
<!DOCTYPE mydoc [
<!ENTITY myextent SYSTEM" ./ myextent.txt">
]>
< mydoc>
< atag name =" fred" value ="& myextent;" />
< / mydoc>
------------------------ -------------------------




我真的不明白你为什么这么做会想要的。如果你希望

值的值字面上是./ myextent.txt,那么你

在<!ENTITY>中不需要SYSTEM。声明(并且不想要

)。如果你真的希望能够在外部文档的

内容中指定值,那么你可以尝试:


-----(你修改过的例子的内容:)-------------


<!DOCTYPE mydoc [

< !ENTITY myextent SYSTEM" ./ myextent.txt">

& myextent;

]>

< mydoc>

< atag name =" fred" value ="& myvalue;" />

< / mydoc>

---------------- ----------------------------------------


-----(myextent.txt的内容)-------------------------

<! ENTITY myvalue" onewordwithoutCR">

---------------------------------- ----------------------


或者,您可以重新设计< atag> (如果你有这样的控制权)那么

& myextent;在内容中,而不是属性。


如果你在想,这不公平,请记住,XML从来都不是
旨在能够直接导入任意文本文件作为

内容(毕竟,如果你的一个单词包含

&符号怎么办?)


-Micah


谢谢Micah,

我真的不明白为什么你会想要那个。
用户在配置

系统时不想修改XML文档,他们更喜欢单词文档。这是一个很长的故事而且我不同意b
同意它,但现在我们有了令人尴尬的要求。

值的价值是字面上的./。 myextent.txt"
不,我们真的需要文件的内容。

然后你可以尝试:
我没想到这个工作(谢谢)。我认为这将是最接近解决方案的



或者,您可以重新设计< atag> (如果你有这样的控制权)
DTD是由第三方指导的,所以不,我们没有控制权。

内容(毕竟,如果你的一个字含有什么一个&符号?)。
我认为我们只需要管理错误。也就是说,了解

问题 - >创建解决方案。你有额外的灵活性和额外的风险,我认为这是公平的。另外请注意,有时我在内部实体中使用

&符号,以便我可以引用

实体中的实体!


,我不清楚为什么会出现这种情况。


问候,

道格拉斯

Micah Cowan< mi ***@cowan.name>在消息新闻中写道:< m3 ************ @ localhost.localdomain> ... 做*********** @ yahoo.com.au (Douglas Reith)写道:

你好,相应的文件?或者更好的是,或许你知道一件作品吗?

通常强大的外部实体以这种方式受限制有点令人沮丧。

示例(myextent.txt只包含一个没有CR的单词):
----------------------------- --------------------
<!DOCTYPE mydoc [
<!ENTITY myextent SYSTEM" ./ myextent.txt">
]>
< mydoc>
< atag name =" fred" value ="& myextent;" />
< / mydoc>
------------------------ -------------------------



我真的不明白为什么你会这么想。如果你希望值的值是字面上的./ myextent.txt,那么你在<!ENTITY>中不需要SYSTEM。声明(并且不想要它)。如果您真的希望能够在外部文档的内容中指定值,那么您可以尝试:

-----(您修改过的示例的内容: )-------------

<!DOCTYPE mydoc [
<!ENTITY myextent SYSTEM" ./ myextent.txt">
& myextent;
]>
< mydoc>
< atag name =" fred" value ="& myvalue;" />
< / mydoc>
------------------------ --------------------------------

-----(myextent的内容。 txt)-------------------------
<!ENTITY myvalue" onewordwithoutCR">
---- -------------------------------------------------- -

或者,你可以重新设计< atag> (如果你有这样的控制权)那么
& myextent;在内容中,而不是属性。

如果您在思考,这不公平,请回想一下,XML从未被设计为能够导入任意文本文件直接作为
内容(毕竟,如果你的一个单词包含
&符号怎么办?)。

-Micah



在文章< c2 ************************** @ posting.google.com> ;,

Douglas Reith< do *********** @ yahoo.com.au>写道:

有人可以告诉我为什么XML规范声明禁止外部实体的属性值?


我认为 - 虽然需要很长时间才能在W3C档案中找到这个

类型的任何参考资料 - 理由是:


- 解析器不必扩展外部实体引用,不像

内部引用;

- 属性应该是可返回的简单的字符串,如果它们包含未展开的(必然是外部的)

实体引用,它们就不会是b $ b。


不幸的是这个解释并没有真正起作用,因为可能会引用外部声明的内部实体,而解析器

可能也不知道它们。

或者更好的是,也许你知道一个解决方法吗?




是的,但它有点乱。


您可以使用外部声明的内部实体(即代替

只将文本放在外部实体中,在外部实体中定义实体定义

好吧,并使它成为一个参数实体)。


或者 - 如果你想在文件中只有替换文本,那么现在你可以做 - b $ b使用外部实体作为参数实体,

在内部实体的定义中引用它。不幸的是

这不太合适:

<!DOCTYPE mydoc [

<!ENTITY%myextent SYSTEM" ./ myextent.txt">

<!ENTITY myintent"%myextent;"> <! - 错!!! - >

]>

< mydoc>

< atag name =" fred" value ="& myintent;" />

< / mydoc>


因为你不能使用参数实体引用在

内部子集中的方式,但是如果你将你的声明放在外部

参数实体中,它将起作用:


< ;!DOCTYPE mydoc [

<!ENTITY%mydecls SYSTEM" mydecls">

%mydecls;

]>

< mydoc>

< atag name =" fred" value ="& myintent;" />

< / mydoc>


在mydecls中有这个:


<!ENTITY%myextent SYSTEM" ./ myextent.txt">

<!ENTITY myintent"%myextent;">


- Richard

-

垃圾邮件过滤器:从.com / .net网站邮寄给我,将我的姓氏放在标题中。


FreeBSD规则!


Hi There,
Can someone please tell me why the XML spec states that an attribute
value with an external entity is forbidden? Or point me to the
appropriate document? Or better still, perhaps you know of a work
around?

It is a little frustrating that the normally powerful external
entities are limited in this fashion.

Example (myextent.txt contains just one word without a CR):
-------------------------------------------------
<!DOCTYPE mydoc [
<!ENTITY myextent SYSTEM "./myextent.txt">
]>
<mydoc>
<atag name="fred" value="&myextent;"/>
</mydoc>
-------------------------------------------------

Error:
-------------------------------------------------
Cannot reference an external general parsed entity ''myextent'' in an
attribute value. Error processing resource...
Line 6, Position 44
<atag name="fred" value="&myextent;"/>
-------------------------------------------------

Thanks for your help,
Douglas

解决方案

do***********@yahoo.com.au (Douglas Reith) writes:

Hi There,
Can someone please tell me why the XML spec states that an attribute
value with an external entity is forbidden? Or point me to the
appropriate document? Or better still, perhaps you know of a work
around?

It is a little frustrating that the normally powerful external
entities are limited in this fashion.

Example (myextent.txt contains just one word without a CR):
-------------------------------------------------
<!DOCTYPE mydoc [
<!ENTITY myextent SYSTEM "./myextent.txt">
]>
<mydoc>
<atag name="fred" value="&myextent;"/>
</mydoc>
-------------------------------------------------



I can''t really understand why you would want that. If you want
the value of value to be literally "./myextent.txt", then you
don''t need SYSTEM in the <!ENTITY> declaration (and don''t want
it). If you really want to be able to specify the value in the
content of an external document, then you could try:

-----(contents of your (modified) example:)-------------

<!DOCTYPE mydoc [
<!ENTITY myextent SYSTEM "./myextent.txt">
&myextent;
]>
<mydoc>
<atag name="fred" value="&myvalue;"/>
</mydoc>
--------------------------------------------------------

-----(contents of myextent.txt)-------------------------
<!ENTITY myvalue "onewordwithoutCR">
--------------------------------------------------------

Or, you could redesign <atag> (if you have such control) so that
&myextent; goes in the content, rather than an attribute.

If you''re thinking, "that''s not fair", recall that XML was never
designed to be able to import arbitrary text files directly as
content (after all, what if your one word contained an
ampersand?).

-Micah


Thanks Micah,

I can''t really understand why you would want that. Users don''t want to modify an XML document when configuring the
system, they prefer one word documents. It''s a long story and I don''t
agree with it but now we have the unenviable requirement.
the value of value to be literally "./myextent.txt" No we really need the contents of the file.
then you could try: I didn''t think of this work around (thanks). I think it will be the
closest we can get to a solution.
Or, you could redesign <atag> (if you have such control) The DTD is directed by a third party, so no, we don''t have control.
content (after all, what if your one word contained an
ampersand?). I''d argue that we''d just have to manage the error. That is, understand
the problem -> create the solution. You have extra flexibility and
extra risk which I think is fair. On another note, sometimes I use
ampersands in internal entities so that I can refer to entities within
entities!

Again, I''m unclear as to why there is a restiction.

Regards,
Douglas
Micah Cowan <mi***@cowan.name> wrote in message news:<m3************@localhost.localdomain>... do***********@yahoo.com.au (Douglas Reith) writes:

Hi There,
Can someone please tell me why the XML spec states that an attribute
value with an external entity is forbidden? Or point me to the
appropriate document? Or better still, perhaps you know of a work
around?

It is a little frustrating that the normally powerful external
entities are limited in this fashion.

Example (myextent.txt contains just one word without a CR):
-------------------------------------------------
<!DOCTYPE mydoc [
<!ENTITY myextent SYSTEM "./myextent.txt">
]>
<mydoc>
<atag name="fred" value="&myextent;"/>
</mydoc>
-------------------------------------------------



I can''t really understand why you would want that. If you want
the value of value to be literally "./myextent.txt", then you
don''t need SYSTEM in the <!ENTITY> declaration (and don''t want
it). If you really want to be able to specify the value in the
content of an external document, then you could try:

-----(contents of your (modified) example:)-------------

<!DOCTYPE mydoc [
<!ENTITY myextent SYSTEM "./myextent.txt">
&myextent;
]>
<mydoc>
<atag name="fred" value="&myvalue;"/>
</mydoc>
--------------------------------------------------------

-----(contents of myextent.txt)-------------------------
<!ENTITY myvalue "onewordwithoutCR">
--------------------------------------------------------

Or, you could redesign <atag> (if you have such control) so that
&myextent; goes in the content, rather than an attribute.

If you''re thinking, "that''s not fair", recall that XML was never
designed to be able to import arbitrary text files directly as
content (after all, what if your one word contained an
ampersand?).

-Micah



In article <c2**************************@posting.google.com >,
Douglas Reith <do***********@yahoo.com.au> wrote:

Can someone please tell me why the XML spec states that an attribute
value with an external entity is forbidden?
I think - though it takes ages to try and find any reference for this
sort of thing in the W3C archives - that the rationale is that:

- parsers don''t have to expand external entity references, unlike
internal ones;
- attributes should be returnable as simple strings, which they
wouldn''t be if they contained unexpanded (necessarily external)
entity references.

Unfortunately this explanation doesn''t really work, since there may
be references to externally-declared internal entities, and parsers
may not know about them either.
Or better still, perhaps you know of a work around?



Yes, but it''s a bit messy.

You could use an externally declared internal entity (i.e. instead of
putting just the text in an external entity, put an entity definition
in the external entity and make it a parameter entity).

Or - if you want to just have the replacement text in the file as you
do now - you could use the external entity as a parameter entity and
refer to it in the definition of an internal entity. Unfortunately
this doesn''t quite work:
<!DOCTYPE mydoc [
<!ENTITY % myextent SYSTEM "./myextent.txt">
<!ENTITY myintent "%myextent;"> <!-- WRONG!!! -->
]>
<mydoc>
<atag name="fred" value="&myintent;"/>
</mydoc>

because you can''t use a parameter entity reference that way in the
internal subset, but if you put your declarations in an external
parameter entity it will work:

<!DOCTYPE mydoc [
<!ENTITY % mydecls SYSTEM "mydecls">
%mydecls;
]>
<mydoc>
<atag name="fred" value="&myintent;"/>
</mydoc>

with this in mydecls:

<!ENTITY % myextent SYSTEM "./myextent.txt">
<!ENTITY myintent "%myextent;">

-- Richard
--
Spam filter: to mail me from a .com/.net site, put my surname in the headers.

FreeBSD rules!


这篇关于Att值中的外部实体:为什么被禁止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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