XQuery 无法选择属性 [英] XQuery unable to select attribute

查看:34
本文介绍了XQuery 无法选择属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了分析一些数据,我目前正在尝试在 XQuery 中选择一个属性.不幸的是,由于某种原因,我无法选择它.

For analyzing some data, I am currently trying to select an attribute in XQuery. Unfortunately, for some reason I can't select it.

考虑示例文档

<myroot>
 <betweennode>
  <asd name="test">
   <asdasd/>
  </asd>
 </betweennode>
</myroot>

XPath /myroot/betweennode/asd/@name 定期返回 test,XQuery

the XPath /myroot/betweennode/asd/@name regulary returns test, the XQuery

for $x in /myroot/betweennode/asd
return $x

返回

<asd name="test">
   <asdasd/>
</asd>

但是 XQuery

for $x in /myroot/betweennode/asd
return $x/@name

不起作用(它在 http://www.xpathtester.com/xquery 和 '[SENR0001] 属性无法序列化:属性名称 {"testInitialize"}.' 当我使用 BaseX 和 doc('mydoc.xml')/myroot/betweennode/asd 在 for 语句中).

does not work (it returns 'ERROR - Cannot create an attribute node (name) whose parent is a document node' in http://www.xpathtester.com/xquery and '[SENR0001] Attributes cannot be serialized:attribute name {"testInitialize"}.' when I use BaseX and doc('mydoc.xml')/myroot/betweennode/asd in the for-statement).

谁能告诉我为什么这不起作用,以及如何在 XQuery 中选择所有属性?

Could anyone give me a hint why this doesn't work, and how selecting all attributes works in XQuery?

推荐答案

您不能在 XQuery 中返回属性.如果您打算返回属性的值,请尝试这种方式:

You can't return attribute in XQuery. If you meant to return value of the attribute, try this way :

for $x in /myroot/betweennode/asd
return data($x/@name)

这篇关于XQuery 无法选择属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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