📜  XML-声明

📅  最后修改于: 2020-11-09 05:25:42             🧑  作者: Mango


本章详细介绍了XML声明。 XML声明包含一些细节,这些细节为XML处理器准备了解析XML文档的准备。它是可选的,但是在使用时,它必须出现在XML文档的第一行。

句法

以下语法显示了XML声明-


每个参数由参数名称,等号(=)和引号内的参数值组成。下表详细显示了上述语法-

Parameter Parameter_value Parameter_description
Version 1.0 Specifies the version of the XML standard used.
Encoding UTF-8, UTF-16, ISO-10646-UCS-2, ISO-10646-UCS-4, ISO-8859-1 to ISO-8859-9, ISO-2022-JP, Shift_JIS, EUC-JP It defines the character encoding used in the document. UTF-8 is the default encoding used.
Standalone yes or no It informs the parser whether the document relies on the information from an external source, such as external document type definition (DTD), for its content. The default value is set to no. Setting it to yes tells the processor there are no external declarations required for parsing the document.

规则

XML声明应遵守以下规则-

  • 如果XML声明存在于XML中,则必须将其作为XML文档的第一行放置。

  • 如果包含XML声明,则它必须包含版本号属性。

  • 参数名称和值区分大小写。

  • 名称总是小写。

  • 放置参数的顺序很重要。正确的顺序是:版本,编码和独立。

  • 可以使用单引号或双引号。

  • XML声明没有结束标记,即

XML声明示例

以下是XML声明的一些示例-

没有参数的XML声明-


具有版本定义的XML声明-


具有所有参数定义的XML声明-


XML声明,所有参数都定义在单引号中-