Re: Problem to Xquery a document from xindice collection

"johan bos" <[email protected]>
Newsgroups gmane.text.xml.xindice.user
Message-ID <[email protected]>
Thanks, I know my problem is the query format
Can anyone drive me to a good tutorial of XPATH query

here the different query I tried:

System.out.println("ADDING MESSAGE FROM PATH & NAME");
MessageDB.addDocument(mailDirectory + 
"dariusjbosSatAug13235020BST2005.xml");

//DOESN'T WORK (But it s fine, I suppose KEY ID is better as the result from 
any query is the KEY.
System.out.println("RETRIEVE MESSAGE FROM NAME");
MessageDB.retrieveDocument("dariusjbosSatAug13235020BST2005.xml");

//WORKS BECAUSE it exists
System.out.println("RETRIEVE MESSAGE FROM KEY");
MessageDB.retrieveDocument("0601a7c0664aa59900000105bf073edf");

// WORKS TOO, OUTPUT is a list of KEY Document
System.out.println("COUNT MESSAGE FROM DB/MAIL");
MessageDB.queryCollection("count(//Message)");

//WORKS, OUTPUT is a list of KEY Document where dariusjbos appears
System.out.println("QUERY MESSAGE WITH DARIUSJBOS AS FROM");
MessageDB.queryCollection("/from/Address/name='dariusjbos'");

//DOESN'T Return ANything but at least no error from the query format
System.out.println("QUERY MESSAGE WITH CONTENT TYPE TEXT");
MessageDB.queryCollection("/content[@type='text/plain']");

//DOESN'T Return ANything but at least no error from the query format
System.out.println("QUERY MESSAGE WITH [email protected] AS FROM");
MessageDB.queryCollection("/from/Address[adrs='mailto:[email protected]']/text()");

//DOESN'T WORK and ERROR for the query
System.out.println("QUERY STRING MESSAGE WITH CONTENT TYPE TEXT");
MessageDB.queryCollection("string(/content[@type='text/plain']");

//DOESN'T Return ANything but at least no error from the query format
System.out.println("QUERY MESSAGE WITH DARIUSJBOS AS FROM v2");
MessageDB.queryCollection("/from/Address/name[. ='dariusjbos']");

So, for summary, can anyone as a good tuto reference website for xpath query
because i tried some, and most of the example doesn't fit (like the one with 
[. =dariusjbos])

What I want, is query adrs and the date from my xml, I suppose it will 
return a list of Key Document from Xindice DB and I have to manage from 
these Key to retrieve the full document

Is there any way to only retrieve part of the XML queried?
It s a mail application so from all the mail stored in Xindice, I want to 
create some sort of listing of message

Thanks in advance

<BLOCKQUOTE style='PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #A0C6E5 
2px solid; MARGIN-RIGHT: 0px'><font 
style='FONT-SIZE:11px;FONT-FAMILY:tahoma,sans-serif'><hr color=#A0C6E5 
size=1>
From:  <i>&quot;Lisa McCabe&quot; 
&lt;[email protected]&gt;</i><br>Reply-To:  
<i>[email protected]</i><br>To:  
<i>&lt;[email protected]&gt;</i><br>Subject:  <i>Re: Problem to 
Xquery a document from xindice collection</i><br>Date:  <i>Mon, 15 Aug 2005 
20:56:51 -0400</i><br>MIME-Version:  <i>1.0</i><br>Received:  <i>from 
mail.apache.org ([209.237.227.199]) by MC8-F24.hotmail.com with Microsoft 
SMTPSVC(6.0.3790.211); Mon, 15 Aug 2005 17:57:11 -0700</i><br>Received:  
<i>(qmail 60799 invoked by uid 500); 16 Aug 2005 00:57:10 
-0000</i><br>Received:  <i>(qmail 60786 invoked by uid 99); 16 Aug 2005 
00:57:10 -0000</i><br>Received:  <i>from asf.osuosl.org (HELO 
asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; 
Mon, 15 Aug 2005 17:57:10 -0700</i><br>Received:  <i>pass (asf.osuosl.org: 
local policy)</i><br>Received:  <i>from [24.248.88.131] (HELO 
mail.myeastern.com) (24.248.88.131) by apache.org (qpsmtpd/0.29) with ESMTP; 
Mon, 15 Aug 2005 17:57:29 -0700</i><br>Received:  <i>from MegaCool 
(unverified [66.212.211.142]) by myeastern-dot-com (MyEastern Mail - 
www.myeastern.com) with ESMTP id 24666502 for 
&lt;[email protected]&gt;; Mon, 15 Aug 2005 20:57:01 
-0400</i><br>Hi,<br><br>Did you try the same query using the commandline 
Xindice to see if your<br>xpath query works? That helps me in firguring out 
my problems. I am doing<br>the same type of stuff and compared our code - 
yours is the same as mine so<br>it should work.<br><br>-Lisa 
McCabe<br><br>PS Good luck meeting your deadline!<br><br>----- Original 
Message -----<br>From: &quot;johan bos&quot; 
&lt;[email protected]&gt;<br>To: 
&lt;[email protected]&gt;<br>Sent: Monday, August 15, 2005 1:57 
PM<br>Subject: Problem to Xquery a document from xindice 
collection<br><br><br> &gt;<br> &gt; Hello Everyone,<br> &gt;<br> &gt; Here 
my problem,<br> &gt; I can connect and create a collection (mail)  in 
xindice 1.1 (from<br> &gt; within my<br> &gt; servlet (tomcat 5))<br> &gt; I 
can add document to this collection (the ugly browser let me see them)<br> 
&gt;<br> &gt; but when i try to make a query using the example function for 
quering<br> &gt; xindice, i got an error such as below: (some of the message 
are from my<br> &gt; debug)<br> &gt;<br> &gt;<br> &gt; trying to register 
database<br> &gt; Database xmldb:xindice://localhost:8080/db is 
connected<br> &gt; Collection xmldb:xindice://localhost:8080/db is 
connected<br> &gt; Collection mail already created<br> &gt; 
org.xmldb.api.base.XMLDBException: org.apache.xmlrpc.XmlRpcException:<br> 
&gt; Error<br> &gt; Compiling XPath Expression: Une étape d'emplacement 
était attendue après<br> &gt; le<br> &gt; jeton ''/'' ou ''//''.<br> &gt; 
at<br> 
&gt;<br>org.apache.xindice.client.xmldb.xmlrpc.CollectionImpl.runRemoteCommand(Colle<br>ctionImpl.java:119)<br> 
&gt; at<br> 
&gt;<br>org.apache.xindice.client.xmldb.xmlrpc.CollectionImpl.query(CollectionImpl.j<br>ava:515)<br> 
&gt; at<br> 
&gt;<br>org.apache.xindice.client.xmldb.XindiceCollection.query(XindiceCollection.ja<br>va:259)<br> 
&gt; at<br> 
&gt;<br>org.apache.xindice.client.xmldb.services.QueryService.query(QueryService.jav<br>a:90)<br> 
&gt; at jmms.MessageDB.queryCollection(MessageDB.java:163)<br> &gt; at 
jmms.JMMSServlet.doMessageToDB(JMMSServlet.java:1009)<br> &gt; at 
jmms.JMMSServlet.doPost(JMMSServlet.java:342)<br> &gt; at 
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)<br> &gt; at 
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)<br> &gt; at<br> 
&gt;<br>org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application<br>FilterChain.java:252)<br> 
&gt; at<br> 
&gt;<br>org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh<br>ain.java:173)<br> 
&gt; at<br> 
&gt;<br>org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja<br>va:213)<br> 
&gt; at<br> 
&gt;<br>org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.ja<br>va:178)<br> 
&gt; at<br> 
&gt;<br>org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126<br>)<br> 
&gt; at<br> 
&gt;<br>org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105<br>)<br> 
&gt; at<br> 
&gt;<br>org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java<br>:107)<br> 
&gt; at<br> 
&gt;<br>org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)<br> 
&gt; at<br> &gt; 
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)<br> 
&gt; at<br> 
&gt;<br>org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConne<br>ction(Http11Protocol.java:744)<br> 
&gt; at<br> 
&gt;<br>org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.jav<br>a:527)<br> 
&gt; at<br> 
&gt;<br>org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWo<br>rkerThread.java:80)<br> 
&gt; at<br> 
&gt;<br>org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.jav<br>a:684)<br> 
&gt; at java.lang.Thread.run(Unknown Source)<br> &gt; Query 
/mail/Message/from/Address/[name='dariusjbos'] return an error<br> &gt; 
XML:DB Exception occured 1 org.apache.xmlrpc.XmlRpcException: Error<br> &gt; 
Compiling XPath Expression: Une étape d'emplacement était attendue après<br> 
&gt; le<br> &gt; jeton ''/'' ou ''//''.<br> &gt;<br> &gt; the xml document i 
try to query look like this:<br> &gt; &lt;?xml version=&quot;1.0&quot; 
encoding=&quot;UTF-8&quot;?&gt;<br> &gt; &lt;Message 
xmlns=&quot;URN:ietf:params:email-xml:&quot;<br> &gt; 
rfc822=&quot;URN:ietf:params:rfc822:&quot;&gt;<br> &gt;     &lt;date&gt;Mon 
Aug 15 19:03:47 CEST 2005&lt;/date&gt;<br> &gt;     &lt;from&gt;<br> &gt;    
      &lt;Address&gt;<br> &gt;             
&lt;adrs&gt;mailto:[email protected]&lt;/adrs&gt;<br> &gt;             
&lt;name&gt;dariusjbos&lt;/name&gt;<br> &gt;         &lt;/Address&gt;<br> 
&gt;     &lt;/from&gt;<br> &gt; &lt;/Message&gt;<br> &gt;<br> &gt; find 
after the function i use to query the mail collection under db:<br> &gt;<br> 
&gt; public static void queryCollection()throws Exception {<br> &gt;     
Collection col = null;<br> &gt;         try {<br> &gt;            String 
driver =<br> &gt; 
&quot;org.apache.xindice.client.xmldb.DatabaseImpl&quot;;<br> &gt;           
  Class c = Class.forName(driver);<br> &gt;<br> &gt;            Database 
database = (Database) c.newInstance();<br> &gt;            
DatabaseManager.registerDatabase(database);<br> &gt;<br> &gt;            col 
=<br> &gt; 
DatabaseManager.getCollection(&quot;xmldb:xindice://localhost:8080/db/mail&quot;);<br> 
&gt;<br> &gt;            String xpath = 
&quot;//Message/from/Address/[name='dariusjbos']&quot;;<br> &gt;            
XPathQueryService service =<br> &gt;               (XPathQueryService) 
col.getService(&quot;XPathQueryService&quot;,<br> &gt; &quot;1.0&quot;);<br> 
&gt;            ResourceSet resultSet = service.query(xpath);<br> &gt;       
      ResourceIterator results = resultSet.getIterator();<br> &gt;           
  while (results.hasMoreResources()) {<br> &gt;               Resource res = 
results.nextResource();<br> &gt;               System.out.println((String) 
res.getContent());<br> &gt;            }<br> &gt;         }<br> &gt;         
catch (XMLDBException e) {<br> &gt;            
System.err.println(&quot;XML:DB Exception occurred &quot; + e.errorCode<br> 
&gt; +<br> &gt; &quot;&quot; + e.getMessage());<br> &gt;         }<br> &gt;  
        finally {<br> &gt;            if (col != null) {<br> &gt;            
    col.close();<br> &gt;            }<br> &gt;         }<br> &gt; }<br> 
&gt;<br> &gt; please I really need to pass this problem (deadline in 3 
days)<br> &gt;<br> &gt; thanks in advance<br> &gt;<br> 
&gt;<br><br></font></BLOCKQUOTE>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.