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

XML评论可以随时随地吗?

发布时间:2020-12-16 07:44:17 所属栏目:百科 来源:网络整理
导读:我写了一个简单的工具来生成使用用户输入的查询的DBUnit XML数据集.我想将在 XML中输入的每个查询作为注释,但是用于生成XML文件的DBUnit API不支持在我想要的位置插入注释(在它生成的数据之上),所以我正在使用以顶部或底部的所有查询进行评论. 所以我的问题
我写了一个简单的工具来生成使用用户输入的查询的DBUnit XML数据集.我想将在 XML中输入的每个查询作为注释,但是用于生成XML文件的DBUnit API不支持在我想要的位置插入注释(在它生成的数据之上),所以我正在使用以顶部或底部的所有查询进行评论.

所以我的问题是:它是有效的XML放在任何一个位置?例如,在XML声明之上:

<!-- Queries used: ... -->
<?xml version='1.0' encoding='UTF-8'?>
<dataset>
  ...
</dataset>

或根节点下方:

<?xml version='1.0' encoding='UTF-8'?>
<dataset>
  ...
</dataset>
<!-- Queries used: ... -->

我计划最初尝试上面的XML声明,但我怀疑这是否是有效的XML,尽管声称从wikipedia:

Comments can be placed anywhere in the tree,including in the text if the content of the element is text or #PCDATA.

如果这样做,我打算发布回来,但是要知道它是否是一个官方的XML标准,这是很好的.

更新:参考my response below为我的测试结果.

根据 XML specification,格式良好的XML文档是:

document ::= prolog element Misc*

prolog是什么

prolog ::= XMLDecl? Misc* (doctypedecl Misc*)?

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

这意味着,如果您想在顶部有评论,则不能有XML类型的声明.

该规范与维基百科同意评论:

2.5 Comments

[Definition: Comments may appear anywhere in a document outside other markup; in addition,they may appear within the document type declaration at places allowed by the grammar. They are not part of the document’s character data; an XML processor MAY,but need not,make it possible for an application to retrieve the text of comments. For compatibility,the string “–” (double-hyphen) MUST NOT occur within comments.] Parameter entity references MUST NOT be recognized within comments.

所有这一切意味着您可以将评论放在其他标记之外的任何地方,除非您带有评论,否则您无法使用XML声明.

然而,虽然在理论上与实践一致,但在实践中并没有这样做,所以我很想知道你的实验如何运作.

(编辑:李大同)

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

    推荐文章
      热点阅读