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

xml – 在BaseX 8.2中使用元素节点测试的XQuery文档节点测试在根

发布时间:2020-12-16 22:46:49 所属栏目:百科 来源:网络整理
导读:在BaseX 8.2中,我试图分配给一个XQuery变量,一个文档节点,其根元素具有特定的名称.源 XML看起来像这样: ?xml version="1.0" encoding="utf-8"?!--A comment--myRootElement/ 要获取文档节点,我使用DocumentTest对其进行类型化检查: declare variable $docn
在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中得到解决.感谢您报告此问题.

(编辑:李大同)

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

    推荐文章
      热点阅读