BaseXXMLデータベースを使用しています。次のようなデータベース内のxmlドキュメントについて考えてみます。
<entries>
<book-entry>
<book>Book 1</book>
<author>Author 1 ABC</author>
<title>Title 1</title>
</book-entry>
<car-entry>
<car>Car 1</car>
<model>Model 1</model>
<price>Price 1 ABC</price>
</car-entry>
</entries>
私は、次のようなさまざまなオプションを使用して検索を実行しようとしています。本のみ、車のみ、本と車の両方を検索します。
xqueryでxml変数を使用して、必要な検索タイプに基づいて検索結果を返そうとしています。
変数値の例:- <types><type>book-entry</type></types>
:book-entriesのみを<types><type>car-entry</type></types>
検索-:car-entriesのみを<types><type>book-entry</type><type>car-entry</type></types>
検索-:book-entriesとcar-entriesを検索
XQueryサンプル:
declare variable $doc_name as xs:string external; (: name of xml document :)
declare variable $search_types as xs:anyAtomicType external; (: one of the example variable values shown above :)
declare variable $search_key as xs:string external; (: eg: ABC :)
for $entry in doc($doc_name)/entries[*[exists($search_types/types/type/text() = node-name(.)) and .//text() contains text $search_key]]
return $entry
上記のクエリは、<types><type>car-entry</type></types>
$ search_typesに渡しますが、テキストの子ノードABCを含む車と本の両方のエントリを返します。
xml変数を使用して検索を制限するにはどうすればよいですか?これを行うためのより良い方法はありますか?また、xml変数に両方のタイプの子ノードがある場合、xqueryは車とエントリの両方を返す必要があります。
ありがとう、ソニー