微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

可以在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.jb51.cc/xml/293470.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。