xml – 在BaseX 8.2中使用元素节点测试的XQuery文档节点测试在根元素之前存在注释.为什么?

在BaseX 8.2中,我试图分配给一个XQuery变量,一个文档节点,其根元素具有特定的名称.源 XML看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<!--A comment-->
<myRootElement/>

获取文档节点,我使用DocumentTest对其进行类型化检查:

declare variable $docnode as document-node(element(myRootElement)) := doc("pathToSourceFile");

但是,我收到以下错误消息:XPTY0004:无法将document-node()视为文档节点(document-node()(myRootElement))…

这是非常意外的,因为如果在根元素< myRootElement>之前没有注释,则赋值成功.这意味着注释的存在使查询失败.

但是,这不是预期的行为,除非XQuery在这方面的行为与XSLT不同(如果是这种情况,请告诉我).根据Michael Kay的说法,在XSLT中(p.671¶6XSLT 2.0和
XPath 2.0 4th Ed.)DocumentTest检查以下内容

The document node must be the root of a tree that corresponds to a well-formed XML document.
Specifically this means that the document node must have exactly one element node,and no text
nodes,among its children. It is allowed to have comments and processing instructions before or
after the element node.

事实上,对Saxon的以下转换,使用相同的输入XML效果很好:

<xsl:transform version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
  <xsl:output method="xml" encoding="utf-8"/>

  <xsl:template match="/">
    <xsl:variable name="docnode" as="document-node(element(myRootElement))" select="."/>
    <xsl:value-of select="$docnode/*/name(.)"/>
  </xsl:template>

</xsl:transform>

对变量docnode的赋值成功,输出为:

<?xml version="1.0" encoding="utf-8"?>myRootElement

那么,为什么带有ElementTest的DocumentTest在带有注释的XML文档之前在Saxon中工作,而不是在BaseX中工作?也许,对于我来说,了解XQuery有一些新的东西.

解决方法

评论中所示,你把一切都搞定了.该错误已在 latest 8.2.1 snapshot中得到解决.感谢您报告此问题.

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念