使用SQL,如果只知道部分值,则可以使用LIKE语句获取结果.但是在XQuery中,我似乎无法以同样的方式搜索我的XML文件.
这是我尝试但不起作用:
for $c in /parent/child where $c/element="*partial strin*" return $c/element
for $c in /parent/child where $c/element="%partial strin%" return $c/element
Run Code Online (Sandbox Code Playgroud)
你根本不需要一个for表达式,你可以只使用一个谓词.对于精确的子串匹配,有以下contains功能:
/parent/child/element[contains(., "partial strin")]
Run Code Online (Sandbox Code Playgroud)
对于更复杂的匹配,您可以将正则表达式与matches函数一起使用:
/parent/child/element[matches(., "^partial\s+strin")]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1815 次 |
| 最近记录: |