问题描述
我试图在 <!doctype/>
声明中定义 non-breakspace entity
.代码:
I am trying to define non breaking space entity
in the <!doctype />
declaration. Code :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [ <!ENTITY nbsp " "> ] />
<html xmlns="http://www.w3.org/1999/xhtml">
.. ....
但是当我从上面的文档创建一个 XDocument 对象时,我得到一个异常
But still when i am creating an XDocument object from the above document, i am getting an exception
Undefined entity  .
我做错了什么?
推荐答案
首先,中外部和内部实体的结合"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [ <!ENTITY nbsp " ">]
是不必要的,因为 http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
包括 www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent
其中包括 <!ENTITY nbsp " ">
与您的完全相同.
Firstly, the combination of external and internal entities in "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [ <!ENTITY nbsp " "> ]
is unnecessary because http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
includes www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent
which includes <!ENTITY nbsp " ">
which is exactly the same as yours.
所以那一点应该是:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
其次,XDocument 默认不验证 DTD.但是,您可以使用适当的设置从 XmlValidatingReader
或 XmlTextReader
中Load
Secondly, XDocument doesn't validate to a DTD by default. However, you can Load
from an XmlValidatingReader
or XmlTextReader
with the appropriate settings
[如果不可能,让它成为可能!]最好将 XmlReader 设置为使用 XmlPreloadedResolver
,因为有很多人在那个 DTD 的 URI 和它包含的 .ent 文件上击中可怜的 W3C,他们完全可以使用它的本地副本(完全可以"我的意思是,如果每个人都愿意,他们会非常高兴停止敲打他们的服务器).除了对他们有好处,对你来说也会更快.
[If it's not possible, make it possible!] it's a good idea to set the XmlReader to use a XmlPreloadedResolver
, because there's a lot of people hitting poor ol' W3C at the URI of that DTD and the .ent files it includes, and they're totally okay with you using a local copy of it (by "totally okay" I mean they'd be really glad if everyone would stop hammering their server quite so much). As well as being good for them, it'll be much faster for you.
这篇关于未定义实体 &nbsp XML 解析异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!