Hi all,
I have trouble getting attributes in using XPath in XQueries using the APIs
 
 
_________________________________________
WHAT I WISH TO DO
 
Here is what I wish to do:
 
I want this XQuery
let $doc := (<titi att='test'><toto att='test2'>coucou</toto></titi>) return $doc//titi/@att
To return the attribute att
 
I have tried many combinations:
let $doc := (<titi att='test'><toto att='test2'>coucou</toto></titi>) return $doc/titi/@att
Or simply
<titi att='test'><toto att='test2'>coucou</toto></titi>/titi/@att
<titi att='test'><toto att='test2'>coucou</toto></titi>//titi/@att
 
 
_______________________________________
DESCRIPTION OF THE ISSUE
 
1) I don't have any error displayed
2) No results are returned
 
I have another strange behaviour with element's item:
If I do
let $doc := (<titi att='test'><toto att='test2'>coucou</toto></titi>) return $doc//toto/text()
or
let $doc := (<titi att='test'><toto att='test2'>coucou</toto></titi>) return $doc/toto/text()
 
I have the result 'coucou'
 
BUT if I do:
let $doc := (<titi att='test'><toto att='test2'>coucou</toto></titi>) return $doc/titi/toto/text() (Well I know that If we consider the standars, this one shouldn't work anyway)
or
let $doc := (<titi att='test'><toto att='test2'>coucou</toto></titi>) return $doc//titi/toto/text() (Should be ok)
 
I have the same behaviour as for the attribute issue except I have the turnaround
 
 
___________________________________
CODE
 
I am using the following code (where 'test' is the String containing the XQuery):
(This is very similar to the method 'exampleToStreamResult()' in the example file QueryAPIExample.java)

      String result = new String();

      try {
       
          final Configuration config = new Configuration();
          final StaticQueryContext sqc = new StaticQueryContext(config);
          final XQueryExpression exp = sqc.compileQuery(test);
          Properties props = new Properties();

          final DynamicQueryContext dynamicContext = new DynamicQueryContext(config);
 
          props.setProperty(OutputKeys.METHOD, "xml");
          props.setProperty(OutputKeys.INDENT, "no");
 
          ByteArrayOutputStream theTest = new ByteArrayOutputStream();
          exp.run(dynamicContext, new StreamResult(theTest), props);
         
          result = theTest.toString();
          result = Utils.removeXmlHeader(result);
          //log.getLogger().debug("THE RESULT ========>" + result + "_");
          System.out.println("THE RESULT ========>" + result + "_");
         
      } catch (XPathException e){
       //log.getLogger().error("Not able to process XQuery expression due to XPath exception =>" + e.getMessage());
       System.out.println("Not able to process XQuery expression due to XPath exception =>" + e.getMessage());
      }

 
Am I doing something wrong ?

Pierre
--
________________________
Pierre Martins
+33 (0) 675 190 455
pierre.martins@gmail.com
pierre.martins@symeria.com