Xhtml Invalid Characters?

六月ゝ 毕业季﹏ 提交于 2019-12-11 13:39:01

问题


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,


回答1:


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.




回答2:


There is a list and and it does permit colons.

The XHTML 1.0 spec says at http://www.w3.org/TR/xhtml1/#h-4.10

... in XHTML 1.0 the id attribute is defined to be of type ID ...

The XML 1.0 spec says at http://www.w3.org/TR/2008/REC-xml-20081126/#id

Values of type ID MUST match the Name production.

And the Name production is defined at http://www.w3.org/TR/2008/REC-xml-20081126/#NT-Name

  [4]       NameStartChar      ::=  ":" |
                       [A-Z] | "_" | [a-z] | [#xC0-#xD6] |
                       [#xD8-#xF6] | [#xF8-#x2FF] |
                       [#x370-#x37D] | [#x37F-#x1FFF] |
                       [#x200C-#x200D] | [#x2070-#x218F] |
                       [#x2C00-#x2FEF] | [#x3001-#xD7FF] |
                       [#xF900-#xFDCF] | [#xFDF0-#xFFFD] |
                       [#x10000-#xEFFFF]

  [4a]      NameChar  ::=   NameStartChar | "-" | "." |
                       [0-9] | #xB7 | [#x0300-#x036F] |
                       [#x203F-#x2040]           

  [5]       Name      ::=   NameStartChar (NameChar)*

And also says above this formal definition:

Document authors are encouraged to use names which are meaningful words or combinations of words in natural languages, and to avoid symbolic or white space characters in names. Note that COLON, HYPHEN-MINUS, FULL STOP (period), LOW LINE (underscore), and MIDDLE DOT are explicitly permitted.

(My emphasis)



来源:https://stackoverflow.com/questions/6471829/xhtml-invalid-characters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!