DB2 Text Search also supports searches in SQL/XML and XQuery. By using a subset of the XPath language with extensions for text search, XML search allows you to index and search XML documents. This page shows you several options to search in XML documents.
This example uses the text search functionality in combination with XMLQUERY(). It returns the value of the author
tag if the bookinfo contains the word 'range'.
SELECT xmlquery('$bi//author' passing bookinfo as "bi")
FROM books
WHERE CONTAINS(bookinfo, 'range') = 1
This example performs the same search as the previous example except that XQuery is used instead.
xquery db2-fn:xmlcolumn-contains
('MYSCHEMA.BOOKS.BOOKINFO', 'range')/bookinfo/author
This example performs the same search as the previous example except that XPath expression is used instead.
SELECT author, year, substr(title,1,30)
FROM books
WHERE CONTAINS( bookinfo
, '@xpath:''/bookinfo/story [.contains("range")]''') = 1
This example shows the use of XPath expression in an XQuery to perform a text search.
xquery db2-fn:xmlcolumn-contains
( 'MYSCHEMA.BOOKS.BOOKINFO'
, '@xpath:''/bookinfo/story[.contains("range")]''')/bookinfo/author