Xhtml无效字符? [英] Xhtml Invalid Characters?

查看:90
本文介绍了Xhtml无效字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在.NET中创建了自定义xhtml valdidator(通过dtd验证+一些附加规则),并且注意到我的验证与w3c验证之间存在差异。



在我的验证器中,当id中有冒号时,我会收到以下错误消息(假设:id = mustang:horse)



(错误)'id'属性根据其数据类型具有无效值。



但是我在w3c上没有得到任何错误这种模式。



我试图在xml / xhtml中为属性找到无效字符列表,但找不到它?



谢谢您的帮助,

解决方案

之所以如此,是因为W3C验证器似乎没有进行名称空间感知的XHTML处理。尽管XHTML文档需要位于XHTML名称空间中,但这实际上是合理的,因为HTML文档未使用名称空间,并且XHTML文档的规范有效结构(如HTML)是由DTD文件定义的,而DTD实际上并不了解名称空间。 / p>

就像@Alochi一样:


ID类型的值必须与名称匹配
生产。


当文档被解析为不支持名称空间时,这是正确的,但如果文档不正确,则为true需要符合名称空间。 XML规范中的命名空间规定, ID必须与NCName产生相匹配,禁止冒号。命名空间感知解析是一种常见的约定,因此,即使文档解析不支持命名空间感知,也可以在ID的值中使用冒号。



摘要:如果忽略名称空间,则 ID 值必须是有效的 Name ,并且可以包含冒号;否则,它必须是有效的 NCName ,并且不能包含冒号。


I have made custom xhtml valdidator in .NET(validating through dtd + some extra rules) and I have noticed a discrepancy between my validation and w3c validation.

In my validator I get the following error when there is colon in the id (let's say : id="mustang:horse")

(Error) The 'id' attribute has an invalid value according to its data type.

But I do not get any errors on w3c for this pattern.

I tried to find a list of invalid characters for an attribute in xml/xhtml but couldn't find it?

Thank you for your help,

解决方案

The reason for this difference is that W3C validator doesn't seem to do namespace aware XHTML processing. Although XHTML documents need to be in the XHTML namespace, this is actually reasonable, because HTML documents are not using namespaces and the normative valid structure of XHTML documents (as HTML) is defined by a DTD file and DTDs are not actually namespace aware.

Like @Alochi already noted:

Values of type ID MUST match the Name production.

This is true when the document is parsed as not namespace aware, but it is not true if the document needs to be namespace conformant. The Namespaces in XML specification states that IDs must match NCName production which explicitly forbids the colon character. Namespace aware parsing is a common convention and therefore using a colon in the value of a id is not recommended even though it is allowed when the document parsing is not namespace aware .

Summary: if namespaces are ignored, an ID value must be a valid Name and it can contain a colon; otherwise it must be a valid NCName and it can't contain a colon.

这篇关于Xhtml无效字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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