可以在XML声明之前发表评论吗?

前端之家收集整理的这篇文章主要介绍了可以在XML声明之前发表评论吗?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
将XML声明之前的注释放在XML文件中可以吗?
<!--
Is this bad to do?
-->
<?xml version="1.0" encoding="utf-8"?>
<someElement />
不,不行

Appendix F of the XML spec说:

Because each XML entity not
accompanied by external encoding
information and not in UTF-8 or UTF-16
encoding must begin with an XML
encoding declaration,in which the
first characters must be ‘< ?xml’,any
conforming processor can detect,after
two to four octets of input,which of
the following cases apply.

啊,但是,F节是非规范的,你说。

那么,section 2.1给出了一个格式良好的XML文档的生产,因此:

[1]     document       ::=       prolog element Misc*

…在section 2.8我们得到了“prolog”的生产:

[22]    prolog     ::=       XMLDecl? Misc* (doctypedecl Misc*)?
[23]    XMLDecl    ::=      '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>'

所以,你可以省略< ?xml声明,但你不能用任何东西前缀。 (顺便提及,“杂项”是评论的类别)。

原文链接:https://www.f2er.com/xml/293470.html

猜你在找的XML相关文章