XPath 中的 NULL 文字 [英] NULL literal in XPath
问题描述
XPath 1.0 或 2.0 中是否存在 NULL 字面量?
Is there a NULL literal in XPath 1.0 or 2.0?
我的用例是我有一个条件(if then else
)XPath 表达式,我想返回 NULL 来表示某个条件.我担心在我的情况下返回空字符串可能不明确,因为它可能是 if then else
表达式的另一部分的有效结果.
My use case is that I have a conditional (if then else
) XPath expression and I want to return NULL to signify a certain condition. I am afraid that returning an empty string might be ambiguous in my case as it could be a valid result of the other part of the if then else
expression.
推荐答案
空序列 ()
可以这样使用.如果路径表达式没有结果,也会返回.
The empty sequence ()
can be used as such. It is also returned if there is no result for a path expression.
let $foo := "foo"
return
if ($foo = ("foo", "bar", "batz")) then
$foo
else
()
您可以使用
let $result := ()
return empty($result)
如果您将第一个 XPath 表达式的结果传递给您的本机代码,您应该能够通过没有结果(空序列/NULL")或有结果字符串(它可能为空).
If you pass the result of the first XPath expression to your native code, you should be able to distinguish "NULL" from the empty string by having no results (empty sequence / "NULL") or having a result string (which could be empty).
这篇关于XPath 中的 NULL 文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!