在 Javascript 中动态执行 xquery 并将结果存储在 JS 变量中 [英] dynamically execute xquery within Javascript and store the result in a JS variable

查看:24
本文介绍了在 Javascript 中动态执行 xquery 并将结果存储在 JS 变量中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我想要做的:

动态执行包含在 Javascript 变量示例中的 XQUERY

var myxquery = For Channels.Channel

where Channel/availability = yes

And Channels.Channel/Label = 'CNN'

Return  EXIST(Channels.Channel/Id)';

var xmltoparse= '<channel>
<available>yes</available>
<label>CNN</label>
</channel>
<channel>
<available>yes</available>
<label>BBC</label>
</channel>'

这意味着对 var xmltoparse 执行 var myxquery 并将 xquery 的结果存储在另一个 var 中.

That will imply executing the var myxquery against the var xmltoparse and store the result of the xquery in another var.

有可能吗?

推荐答案

是的,通过使用 eval().但这会使您的 Web 服务暴露于注入攻击中(并且这种特定模式将使其变得非常容易).这就是为什么通常不推荐这样做的原因.

Yes, by using eval(). But that will expose your webservice to injection attacks (and this specific pattern will make it really easy). This is why it is generally not recommended, ever.

但是,如果您无论如何都需要这样做,您可以创建一个 XQY 端点,它将字符串作为参数,然后将该字符串的值传递给 eval().调用 eval() 的确切方法会因您的 XQuery 处理器而异,因为它没有在规范中定义.即:在 eXist 中,它是 util:eval();在 MarkLogic 中,它是 xdmp:eval();等

However, if you needed to do it anyway, you could create an XQY endpoint that takes a string as a parameter and then passes the value of that string to eval(). The exact way to inboke eval() will vary based on your XQuery processor, since it's not defined in the spec. I.e.: In eXist, it's util:eval(); in MarkLogic it's xdmp:eval(); etc.

如果您必须使用这种模式,那么请使用一切必要的方法来锁定它:强身份验证、限制用户执行 eval 的能力,甚至可能在执行之前检查字符串.

If you must use this pattern, then use every means necessary to lock it down: strong authentication, limit the capabilities of the user executing the eval, maybe even inspect the string before executing it.

这篇关于在 Javascript 中动态执行 xquery 并将结果存储在 JS 变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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