You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by Steven Traut <st...@bea.com> on 2005/04/25 21:46:09 UTC

XQuery syntax error: unexpected token "$"

Hello all -- Anyone know why the execQuery method should choke on line  
1 of the following expression? Am I missing something about the $this  
variable?

                 "for $e in $this/xq:employees/xq:employee " +
                 "let $s := $e/xq:address/xq:state " +
                 "where $s = 'WA' " +
                 "return $e"

Saxon is on the classpath. Artifacts below.

Thanks,
Steve

Message/exception:

Error
   XQuery syntax error on line 1 in `... variable $this external;or $e`:
     Unexpected token "$" beyond end of query
Exception in thread "main" java.lang.RuntimeException:  
java.lang.reflect.InvocationTargetException
	at  
org.apache.xmlbeans.impl.store.SaxonXBeansDelegate.createQueryInstance(S 
axonXBeansDelegate.java:112)
	at  
org.apache.xmlbeans.impl.store.Query$SaxonQueryImpl.createSaxonCompiledQ 
uery(Query.java:153)
	at org.apache.xmlbeans.impl.store.Query.getCompiledQuery(Query.java:91)
	at org.apache.xmlbeans.impl.store.Query.getCompiledQuery(Query.java:53)
	at org.apache.xmlbeans.impl.store.Query.cursorExecQuery(Query.java:48)
	at org.apache.xmlbeans.impl.store.Cursor._execQuery(Cursor.java:1328)
	at org.apache.xmlbeans.impl.store.Cursor._execQuery(Cursor.java:1323)
	at org.apache.xmlbeans.impl.store.Cursor.execQuery(Cursor.java:3814)
	at  
org.apache.xmlbeans.samples.xquery.ExecQuery.selectEmpsByStateCursor(Exe 
cQuery.java:26)
	at  
org.apache.xmlbeans.samples.xquery.XQueryXPath.start(XQueryXPath.java: 
54)
	at  
org.apache.xmlbeans.samples.xquery.XQueryXPath.main(XQueryXPath.java: 
45)
Caused by: java.lang.reflect.InvocationTargetException
...


Java code:


     final static String m_namespaceDeclaration = "declare namespace xq='http://xmlbeans.apache.org/samples/xquery/employees';";

     public boolean selectEmpsByStateCursor(XmlObject empDoc)
     {
         boolean hasResults = false;
         XmlCursor empCursor = empDoc.newCursor();
         empCursor.toNextSibling();
         XmlObject resultXml = null;

         String queryExpression = "for $e in $this/xq:employees/xq:employee " +
                 "let $s := $e/xq:address/xq:state " +
                 "where $s = 'WA' " +
                 "return $e";

         XmlCursor resultCursor =  
empCursor.execQuery(m_namespaceDeclaration + queryExpression);

         if (resultCursor.getSelectionCount() > 0)
         {
             hasResults = true;
             resultXml = resultCursor.getObject();
             System.out.println(resultXml.toString());
             resultCursor.dispose();
             empCursor.dispose();
         }
         return hasResults;
     }


XML bound to empDoc param above:

<?xml version="1.0" encoding="UTF-8"?>

<employees xmlns="http://xmlbeans.apache.org/samples/xquery/employees">
   <employee>
     <name>Fred Jones</name>
     <address location="home">
       <street>900 Aurora Ave.</street>
       <city>Seattle</city>
       <state>WA</state>
       <zip>98115</zip>
     </address>
     <address location="work">
       <street>2011 152nd Avenue NE</street>
       <city>Redmond</city>
       <state>WA</state>
       <zip>98052</zip>
     </address>
     <phone location="work">(425)555-5665</phone>
     <phone location="home">(206)555-5555</phone>
     <phone location="mobile">(206)555-4321</phone>
   </employee>
   <employee>
     <name>Sally Smith</name>
     <address location="home">
       <street>1430 Oak Place</street>
       <city>Salem</city>
       <state>OR</state>
       <zip>97125</zip>
     </address>
     <address location="work">
       <street>765 Main St.</street>
       <city>Keizer</city>
       <state>OR</state>
       <zip>97103</zip>
     </address>
     <phone location="work">(503)555-3856</phone>
     <phone location="home">(503)555-6951</phone>
     <phone location="mobile">(503)555-5152</phone>
   </employee>
   <employee>
     <name>Gladys Kravitz</name>
     <address location="home">
       <street>1313 Mockingbird Lane</street>
       <city>Seattle</city>
       <state>WA</state>
       <zip>98115</zip>
     </address>
     <address location="work">
       <street>2011 152nd Avenue NE</street>
       <city>Redmond</city>
       <state>WA</state>
       <zip>98052</zip>
     </address>
     <phone location="work">(425)555-6897</phone>
     <phone location="home">(206)555-6594</phone>
     <phone location="mobile">(206)555-7894</phone>
   </employee>
</employees>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org