Hi,

I'm trying to use XQuery in XMLBeans.

Well using samples in XMLBeans package, all work fine, but when i write my
XQuery it is not work.

I wrote my XQuery and validate in XML Spy and all work fines, but when i put
my xquery in XMLBeans this not return nothing.


----------------------------------------------------------------------------------------------------------------------------------------------
XQUERY -----

declare namespace n1='http://xxxxx.com.br/score/probability';
for $x in doc("score.xml")/n1:scores/score
  let $s := $x/name
  where $s = 'Score1'
return $x
----------------------------------------------------------------------------------------------------------------------------------------------
XML -----

<?xml version="1.0" encoding="UTF-8"?>
<n1:scores 
xsi:schemaLocation="http://xxxxx.com.br/score/probabilityscore_probability.xsd
" xmlns:n1="http://xxxxx.com.br/score/probability"; xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance";>
<score>
<class>0</class>
<rating>String</rating>
<probability>String</probability>
<initial_score>0</initial_score>
<end_score>0</end_score>
<name>Score1</name>
</score>
<score>
<class>0</class>
<rating>String</rating>
<probability>String</probability>
<initial_score>0</initial_score>
<end_score>0</end_score>
<name>Score2</name>
</score>
<score>
<class>0</class>
<rating>String</rating>
<probability>String</probability>
<initial_score>0</initial_score>
<end_score>0</end_score>
<name>Score3</name>
</score>
</n1:scores>
----------------------------------------------------------------------------------------------------------------------------------------------
RETURN  XML Spry-----
 <score xmlns:n1=http://xxxxx.com.br/score/probability xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance";><class>0</class><rating>String</
rating><probability>String</probability><initial_score>0</initial_score><
end_score>0</end_score><name>Score1</name></score>

----------------------------------------------------------------------------------------------------------------------------------------------
CODE -----



String newQuery="declare namespace n1='http://xxxxx.com.br/score/probability';
"+
"for $x in $this/n1:scores/score "+
"let $s := $x/name "+
"where $s = 'Score1' "+
"return $x";

XmlCursor scoreCursor = scoreDoc.newCursor();
scoreCursor.toNextToken();
XmlCursor resultCursor = scoreCursor.execQuery(newQuery);
System.*out*.println("The query results : ");
System.*out*.println(resultCursor.getObject().toString() + "\n");
----------------------------------------------------------------------------------------------------------------------------------------------
RETURN  PROGRAM-----


The query results :

<xml-fragment/>





Thanks for any help.

Gustavo

Reply via email to