kal*_*nma 7 regex xquery marklogic
我正在尝试使用fn:matches正则表达式的XQuery ,但XQuery的MarkLogic实现似乎不允许十六进制字符表示.以下给出了" 无效的正则表达式 "错误.
(: Find text containing non-ISO-Latin characters :)
let $regex := '[^\x00-\xFF]'
let $results := fn:collection('mydocs')//myns:myelem[fn:matches(., $regex)]
let $count := fn:count($results)
return
<figures count="{$count}">
{ $results }
</figures>
Run Code Online (Sandbox Code Playgroud)
但是,这个没有给出错误.
let $regex := '[^a-zA-Z0-9]'
let $results := fn:collection('mydocs')//myns:myelem[fn:matches(., $regex)]
let $count := fn:count($results)
return
<figures count="{$count}">
{ $results }
</figures>
Run Code Online (Sandbox Code Playgroud)
在MarkLogic的XQuery实现中,有没有办法使用十六进制字符表示,或者给出相同结果的替代方法?
XQuery可以在字符串中使用数字字符引用,与XML和HTML的方式非常相似:
十进制:" "
十六进制:( "�a;"或只是"&#a;")
但是,您不能代表某些字符:<= "	"例如.
XQuery中没有正则表达式类型(您只使用字符串作为正则表达式),因此您可以在正则表达式中使用字符引用:
fn:matches("a", "[^	-ÿ]")
(: => xs:boolean("false") :)
Run Code Online (Sandbox Code Playgroud)
更新:这是关于字符引用的XQuery 1.0规范:http://www.w3.org/TR/xquery/#dt-character-reference.
根据一些简短的测试,我认为MarkLogic强制执行XML 1.1字符引用规则:http://www.w3.org/TR/xml11/#charsets
对于后代,这里是XML 1.0规则:http://www.w3.org/TR/REC-xml/#charsets