NULL literal in XPath

戏子无情 提交于 2019-12-11 18:59:47

问题


Is there a NULL literal in XPath 1.0 or 2.0?

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.


回答1:


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
    ()

You can check for an empty sequence using

let $result := ()
return empty($result)

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).



来源:https://stackoverflow.com/questions/17374407/null-literal-in-xpath

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!