必须在 XML 声明之后换行吗? [英] Must a new line follow the XML declaration?

查看:43
本文介绍了必须在 XML 声明之后换行吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个有效的 XML 实例吗?XML 声明和根节点之间没有任何内容.

Is this one a valid XML instance? It has nothing between the the XML declaration and the root node.

<?xml version="1.0" encoding="UTF-8"?><data></data>

我自己在 XML 规范中找不到合适的位置,希望有人能帮助我...

I could not find the right place in the XML specification myself and hope that somebody will help me...

推荐答案

规范(参见 2.8 Prolog 和文档类型声明) 不需要(但允许)在 XML 声明之后使用换行符.

The spec (see 2.8 Prolog and Document Type Declaration) does not require (but does allow) a newline to follow the XML Declaration.

正式写成:

[16] PI ::= '' Char*)))?'?>'
...
[22] 序言 ::= XMLDecl?Misc* (doctypedecl Misc*)?
[23] XMLDecl ::= '<?xml' VersionInfo EncodingDecl?SDDecl??'?>'
...
[27] 其他 ::= 评论 |PI |S

正如您在 [22] prolog 中所见,XML 声明是可选(请参阅符号后的问号)和零、一个或多个(请参阅星号)Misc 可以跟在以下内容之后:注释、其他处理指令(PI)或空格(S).空格包括换行符.

As you can see in [22] prolog the XML Declaration is optional (see the questionark after the symbol) and zero, one or more (see the star) Misc can follow which are: Comments, other Processing Instructions (PI) or Whitespace (S). Whitespace includes the newline.

因为 Misc 在这里是可选的,所以可以但不必在声明后跟一个换行符.

Because Misc is optional here, there can but need not follow a newline after the declaration.

这篇关于必须在 XML 声明之后换行吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆