XPath 2.0自定义功能调用语法分析

发布于 2025-02-01 08:09:52 字数 509 浏览 2 评论 0原文

我想知道是否有任何简单的方法来检查XPath 2.0表达式的句法正确性,包括检查自定义功能调用的正确性。

例如:

有一个自定义函数如下:

<function signature="my:foo($p as number, $q as number) as number">
   <sequence value="$p + $q"/>
</function>

因此,应使用以下表达式调用此函数:

my:foo(a, b)

但是,我们无法仅使用XPATH 2.0解析器根据其定义来检查函数调用是否根据其定义正确。 XPATH 2.0解析器将接受表达式:

my:foo(a)
my:foo(a, b, c, d, e)
my:foo((a, b, c, d))

问题是是否有任何简单的方法可以检查自定义功能调用的正确方法(没有类型检查,只有数量参数)?

I was wondering whether there is any easy way of checking syntactic correctnes of XPath 2.0 expressions including checking correctness of custom functions invocations.

For example:

there is a custom function defined as follows:

<function signature="my:foo($p as number, $q as number) as number">
   <sequence value="$p + $q"/>
</function>

so this function should be invoked with the expression like:

my:foo(a, b)

However, we cannot check whether the function call is syntacticaly correct according to its definition using only XPath 2.0 parser. XPath 2.0 parser will accept expressions like:

my:foo(a)
my:foo(a, b, c, d, e)
my:foo((a, b, c, d))

The question is whether there is any easy way to check correctnes of custom functions invocations (without type checking, only number of arguments)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泼猴你往哪里跑 2025-02-08 08:09:52

请注意,从技术上讲,我们在这里谈论函数调用的语义正确性,而不是其句法正确性。也就是说,我们并不是简单地检查它符合XPath语法,而是在可用函数签名的上下文中呼叫有意义。

我希望大多数XPATH引擎在检查句法正确性时同时检查语义正确性。例如,如果您使用saxon的界面xpathcompiler.compile(“ my:foo(a,b)”) ,只有当my:foo#2 在静态上下文中定义为一个函数,声明的参数类型与提供元素节点作为参数兼容。

如何将功能添加到静态上下文是另一个问题。您已经给出了基于XML的函数实现的定义:

<function signature="my:foo($p as number, $q as number) as number">
   <sequence value="$p + $q"/>
</function>

将其变成萨克森理解的东西需要一些精力。它有两个方面:使XPath编译器了解功能签名,并使XPATH运行时了解功能主体。我真的不确定您在这里想到什么。

Note that technically, we are talking here about the semantic correctness of the function call, not its syntactic correctness. That is, we're not checking simply that it conforms to the XPath grammar, but that the call makes sense in the context of the available function signatures.

I would expect most XPath engines to check semantic correctness at the same time as they check syntactic correctness. For example, if you process the expression using Saxon's interface XPathCompiler.compile("my:foo(a, b)"), the call will succeed only if my:foo#2 is defined as a function in the static context, with declared argument types compatible with supplying element nodes as the arguments.

How to add functions to the static context is another question. You've given an XML-based definition of a function implementation:

<function signature="my:foo($p as number, $q as number) as number">
   <sequence value="$p + $q"/>
</function>

Turning that into something that Saxon understands will require some effort. There are two sides to it: making the XPath compiler understand the function signature, and making the XPath runtime understand the function body. I'm really not sure what you have in mind here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文