使用 Xquery,如何将变量嵌入到以下 xml 文档的 xquery 表达式中。我有以下 xml 文档
<CD>
<TITLE>Picture book</TITLE>
<ARTIST>Simply Red</ARTIST>
<COUNTRY>EU</COUNTRY>
<COMPANY>Elektra</COMPANY>
<PRICE>7.20</PRICE>
<YEAR>1985</YEAR>
</CD>
<CD>
<TITLE>Red</TITLE>
<ARTIST>The Communards</ARTIST>
<COUNTRY>UK</COUNTRY>
<COMPANY>London</COMPANY>
<PRICE>7.80</PRICE>
<YEAR>1987</YEAR>
</CD>
<CD>
<TITLE>Unchain my heart</TITLE>
<ARTIST>Joe Cocker</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>EMI</COMPANY>
<PRICE>8.20</PRICE>
<YEAR>1986</YEAR>
</CD>
我需要发出查询以返回 YEAR > 1986 的所有 CD。我希望将“where”子句的组件作为变量,我的意思是存储YEAR > 1986
到三个变量中并在查询中使用变量,这里我到目前为止
String queryString =
"declare variable $field :=" +"YEAR"+";"+
"declare variable $operator :=" +">"+";"+
"declare variable $value :=" +"1986"+";"+
"declare variable $docName as xs:string external;" + sep +
"for $cat in doc($docName)/*/"+ "CD" +
"where $cat/$field $operator $value" +
"order by $cat/$field" +
"return $cat";
XQExpression expression = conn.createExpression();
expression.bindString(new QName("docName"), filename,
conn.createAtomicType(XQItemType.XQBASETYPE_STRING));
results = expression.executeQuery(queryString);
return results.getSequenceAsString(new Properties());
我的查询表达式不完美,我想我在使用变量时遇到了麻烦,有人可以帮我解决这个问题吗?谢谢