我想知道如何在 XQuery 中使用通配符。
我有两行代码,可以从 xml 文件中获得我想要的返回值:
for $phrase in //phrases[@pPhrase="Phrase1.mp3"]
return concat(string($phrase/@pPhrase), ", ",$phrase/ancestor::entrance/string(@name))
我遇到的问题是,有时我不知道我要查找的 mp3 文件的确切名称。
所以,如果这是一个 SQL 查询,我会输入:
其中 pPhrase LIKE '%.mp3'
。
for $phrase in //phrases[@pPhrase LIKE ='%.mp3']
上面的行当然不起作用,那么正确的语法是什么?
最佳答案
你可以使用
//phrases[contains(@pPhrase,'.mp3']
或更准确地说(自 xPath 2.0 起)
//phrases[ends-with(@pPhrase,'.mp3']
关于xml - XQuery 中的通配符对应于 SQL 中的 [where LIKE '%.mp3' ],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72950684/