通过XCC将XQuery xml元素作为外部变量传递给Marklogic

我们有一个相当简单的XQuery和Groovy代码如下.
Xquery代码
declare variable $criteria as element(criteria) external ;

<scopedInterventions>{
$criteria/equals/field
}</scopedInterventions>

这是试图调用它的测试代码

def uri = new URI("xcc://admin:admin@localhost:8001")

def contentSource = ContentSourceFactory.newContentSource(uri)

def request = session.newModuleInvoke("ourQuery.xqy")
def criteria =
"""<criteria>
<equals>
<field>status</field>
<value>draft</value>
</equals>
</criteria>
"""

request.setNewVariable("criteria",ValueType.ELEMENT,criteria);

session.submitRequest(request).asString()
}

我们在执行时遇到此错误

Caused by: com.marklogic.xcc.exceptions.XQueryException: XDMP-LEXVAL:
xs:QName(“element()”) — Invalid lexical value “element()” [Session:
user=admin,cb={default} [ContentSource: user=admin,cb={none}
[provider: address=localhost/127.0.0.1:9001,pool=1/64]]] [Client:
XCC/5.0-3,Server: XDBC/5.0-3] expr: xs:QName(“element()”) at
com.marklogic.xcc.impl.handlers.ServerExceptionHandler.handleResponse(ServerExceptionHandler.java:34)
at
com.marklogic.xcc.impl.handlers.EvalRequestController.serverDialog(EvalRequestController.java:83)
at
com.marklogic.xcc.impl.handlers.AbstractRequestController.runRequest(AbstractRequestController.java:84)
at
com.marklogic.xcc.impl.SessionImpl.submitRequestInternal(SessionImpl.java:373)
at
com.marklogic.xcc.impl.SessionImpl.submitRequest(SessionImpl.java:356)
at
com.zynx.galen.dataaccess.MarkLogicUtilities.executeQueryWithMultipleXMLParameters(MarkLogicUtilities.groovy:52)
at
com.zynx.galen.repositories.ScopedInterventionService.getScopedInterventionsByCriteria(ScopedInterventionService.groovy:20)
… 1 more

任何帮助都会非常感激.

http://docs.marklogic.com/javadoc/xcc/overview-summary.html有答案,我想:

Passing Variables With Queries

Variables may be bound to Request objects. When an execution request
is issued to the server with Session.submitRequest(Request) all the
variables currently bound to the Request object are sent along and
defined as external variables in the execution context in the server.

XCC lets you create XdmNodes and XdmSequences,as well as XdmAtomic
values. However,in the initial XCC release values of this type may
not be bound as external variables because MarkLogic Server cannot yet
accept them. This capability is anticipated for a future release.

由于不支持XdmNode,我认为它的子类XdmElement也不受支持.所以这些类只对响应有用,而不是请求.错误消息可能会有所改进.

您可以使用setNewStringVariable传递XML字符串,然后在XQuery模块中调用xdmp:unquote.请注意,xdmp:unquote返回文档节点,因此/ * XPath步骤会生成其根元素.

declare variable $xml-string as xs:string external ;
declare variable $criteria as element(criteria) := xdmp:unquote($xml-string)/* ;
....

相关文章

引言 NOKIA 有句著名的广告语:“科技以人为本”。任何技术都是为了满足人的生产生活需要而产生的。具体...
Writer:BYSocket(泥沙砖瓦浆木匠) 微博:BYSocket 豆瓣:BYSocket Reprint it anywhere u want. 文章...
Writer:BYSocket(泥沙砖瓦浆木匠) 微博:BYSocket 豆瓣:BYSocket Reprint it anywhere u want. 文章...
http://blog.jobbole.com/79252/ 引言 NOKIA 有句著名的广告语:“科技以人为本”。任何技术都是为了满...
(点击上方公众号,可快速关注) 公众号:smart_android 作者:耿广龙|loonggg 点击“阅读原文”,可查看...
一、xml与xslt 相信所有人对xml都不陌生,其被广泛的应用于数据数据传输、保存与序列化中,是一种极为强...