加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

在文档格式良好的XML中有多个XML声明吗?

发布时间:2020-12-16 23:17:30 所属栏目:百科 来源:网络整理
导读:在同一个文档格式良好的 XML中有两个 XML声明吗? ?xml version="1.0" encoding="UTF-8"?a ?xml version="1.0" encoding="UTF-8"? b hello /b/a 我相信它不是,但我找不到支持我的消息来源. 从Extensible Markup Language (XML) 1.0 起 Definition: XML docum
在同一个文档格式良好的 XML中有两个 XML声明吗?

<?xml version="1.0" encoding="UTF-8"?>
<a>
 <?xml version="1.0" encoding="UTF-8"?>
 <b>
  hello
 </b>
</a>

我相信它不是,但我找不到支持我的消息来源.

从Extensible Markup Language (XML) 1.0 起

Definition: XML documents SHOULD begin with an XML declaration which
specifies the version of XML being used.

那个讨厌的词“应该”就在那里.理想情况下,文档以XML声明开头.它没有说明在文档中有另一个.

The document type declaration MUST appear before the first element in
the document.

这很接近,但它没有谈论XML声明本身,即使它应该在它之前.

解决方法

在格式良好的XML中只允许一个XML声明,并且它必须位于顶部(如果有的话).

必须在顶部

请参阅XML Recommendation的Well-Formed XML Documents部分中的文档定义:

[1]     document ::= prolog element Misc*

然后检查prolog:

[22]    prolog   ::= XMLDecl? Misc* (doctypedecl Misc*)?

然后是XMLDecl:

[23]    XMLDecl  ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>'

因此,我们看到EBNF允许在文档顶部进行XML声明.

只有一个

Processing instructions

[16]    PI       ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'
[17]    PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l'))

…通常可能在其他地方发生,但是由于PITarget和此声明的定义,排除了第二个XML声明:

The target names ” XML “,” xml “,and so on are reserved for standardization in this or future versions of this specification.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读