我对 XML 有基本的了解。我的问题是为什么有必要提及在 XML 文档开头使用的编码以及为什么需要编码?
最佳答案
It is not required , 虽然通常你可能想包括它:
In the absence of external character encoding information (such as MIME headers), parsed entities which are stored in an encoding other than UTF-8 or UTF-16 must begin with a text declaration (see 4.3.1 The Text Declaration) containing an encoding declaration.
因此,例如,当通过 HTTP 传输 XML 时,XML 解析器可能会像这样使用 Content-Type
header 中的值:
Content-Type application/xml; charset=UTF-8
但是一旦该文档存储在本地,它就不会包含此信息 - 因此将编码包含到 XML 文档的声明部分似乎是个好主意。
关于xml - 为什么需要 XML 编码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15367908/