我想编写一个XQuery查询,返回包含任何 XML元素的XML元素,其中包含关键字,例如 '倒计时' 。我写了以下查询但无法正常工作:
for $entity in collection('data2.dbxml')//movie
where contains( $entity/ * , 'countdown' ) return $entity
为什么以及如何编写正确的查询?
示例XML文档是
<?xml version="1.0" encoding="UTF-8"?>
<movies xmlns:xlink= " http://www.w3.org/1999/xlink " >
<movie>
<title> " 100 Jahre - Der Countdown " (1999) {1998 - Der Präsident und das Mädchen (#10.8)}
</title>
<url>http://www.imdb.com/Title? " 100 Jahre - Der Countdown " (1999) {1998 - Der Präsident und
das Mädchen (#10.8)}
</url>
<overview>
<releasedates>
<releasedate>Germany 30 December 1999
</releasedate>
</releasedates>
</overview>
<cast>
<actors>
<actor>
<name>Brückner Christian
</name>
<character>Narrator
</character>
</actor>
<actor>
<name>Clinton Bill (I)
</name>
<character>(archive footage) Himself
</character>
</actor>
<actor>
<name>Lewinsky Monica
</name>
<character>(archive footage) Herself
</character>
</actor>
</actors>
</cast>
<additional_details>
</additional_details>
<fun_stuff>
</fun_stuff>
</movie>
</movies>
答案 0 :(得分:1)
XQuery区分大小写,“倒计时”和“倒计时”不一样。此外,contains($string, $needle)
需要单个字符串,而不是序列。幸运的是,XQuery通过连接所有文本节点隐式地将任何元素(包括其子树)强制转换为字符串。
for $movie in collection('data2.dbxml')//movie
where contains(lower-case($movie), 'countdown')
return $movie
答案 1 :(得分:0)
理想情况下,您可能希望使用XQuery全文,因为它需要区分大小写等:
for $entity in collection('data2.dbxml')//movie
where $entity contains text 'countdown'
return $entity
如果您无法访问它,请使用Jens提供的答案。