XML 属性中哪些字符无效(除非已编码)?

问题描述:

我不敢相信我无法轻松访问此信息,因此:

I can't believe I can't find this information easily accessible, so:

1) 哪些字符不能在没有实体编码的情况下合并到 XML 属性中?

1) Which characters cannot be incorporated in an XML attribute without entity-encoding them?

显然,您需要对引号进行编码.> 怎么样?还有什么?

Obviously, you need to encode quotes. What about < and >? What else?

2) 官方名单具体在哪里?

2) Where exactly is the official list?

这里是属性值中允许的内容.

'"' ([^<&"] | Reference)* '"'  |  "'" ([^<&'] | Reference)* "'" 

所以,你不能:

  • 打开/关闭属性值的相同字符(任一 '")
  • 裸露的&符号(& 必须是 &amp;)
  • 一个左尖括号( 必须是 &lt;)
  • the same character that opens/closes the attribute value (either ' or ")
  • a naked ampersand (& must be &amp;)
  • a left angle bracket (< must be &lt;)

您也不应该使用任何完全不合法的字符XML 文档中的任何位置(例如表单提要等).

You should also not being using any characters that are outright not legal anywhere in an XML document (such as form feeds, etc).