所以我的问题是:它是有效的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为我的测试结果.
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声明.
然而,虽然在理论上与实践一致,但在实践中并没有这样做,所以我很想知道你的实验如何运作.