2013-01-04 35 views
0

我有一個XHTML文件,這一行:星號在XML屬性值

<tr id="some-string-with-a-*"> 

,我得到驗證錯誤:

Syntax of value for attribute id of tr is not valid

我把它改成&#42;,我仍然會得到相同的錯誤。
有什麼建議嗎?

回答

1

不能使用星號:

ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

XHTML specification的片段標識符部分:

Note that the collection of legal values in XML 1.0 Section 2.3, production 5 is much larger than that permitted to be used in the ID and NAME types defined in HTML 4. When defining fragment identifiers to be backward-compatible, only strings matching the pattern [A-Za-z][A-Za-z0-9:_.-]* should be used. See Section 6.2 of [HTML4] for more information.

需要注意的是,如果你不希望支持向後兼容性,有根據XML允許附加字符,但星號不在該列表中:

http://www.w3.org/TR/REC-xml/#NT-Name

+0

感謝您的好解釋。不過,我可以使用某個實體,即'â',它不會引發驗證錯誤。這就是爲什麼我認爲可能有解決方法的一些方法。 – theta