Xquery in java embedded database

View: New views
6 Messages — Rating Filter:   Alert me  

Xquery in java embedded database

by karanjit cheema :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

hi

i want to process some xqueries for an embedded instance of eXist in a
java application.
i am using the following code as given in the examples:

           String query = readFile(args[0]);

            Collection col =
                DatabaseManager.getCollection(URI + DBBroker.ROOT_COLLECTION);
            XQueryService service =
                (XQueryService) col.getService( "XQueryService", "1.0" );
            service.setProperty( OutputKeys.INDENT, "yes" );
            service.setProperty( OutputKeys.ENCODING, "UTF-8" );
            CompiledExpression compiled = service.compile( query );
            ResourceSet result = service.execute( compiled );
            Properties outputProperties = new Properties();
            outputProperties.setProperty(OutputKeys.INDENT, "yes");

SAXSerializer serializer =
SAXSerializer)SerializerPool.getInstance().borrowObject(SAXSerializer.class);
            serializer.setOutput(new OutputStreamWriter(System.out),
outputProperties);

            for ( int i = 0; i < (int) result.getSize(); i++ ) {
                XMLResource resource = (XMLResource)
result.getResource( (long) i );
                resource.getContentAsSAX(serializer);
            }

            SerializerPool.getInstance().returnObject(serializer);
            long rtime = System.currentTimeMillis() - start;
            System.out.println("hits:          " + result.getSize());
            System.out.println("query time:    " + qtime);
            System.out.println("retrieve time: " + rtime);




any xquery i write in the file gives a hit only when i write in the
form of a conditional expression that specifies the search criteria.
even if the tags do not exist in my xml file.

can some 1 please give a few examples of how to retrieve the data of a
specific tag after matching it under certain conditions.





Karanjit Cheema

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Exist-open mailing list
Exist-open@...
https://lists.sourceforge.net/lists/listinfo/exist-open

Re: Xquery in java embedded database

by Dmitriy Shabanov :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, 2009-11-04 at 21:13 +0530, karanjit cheema wrote:
> any xquery i write in the file gives a hit only when i write in the
> form of a conditional expression that specifies the search criteria.
> even if the tags do not exist in my xml file.
>
> can some 1 please give a few examples of how to retrieve the data of a
> specific tag after matching it under certain conditions.

Can you share xquery script?
 
--
Cheers,

Dmitriy Shabanov


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Exist-open mailing list
Exist-open@...
https://lists.sourceforge.net/lists/listinfo/exist-open

Re: Xquery in java embedded database

by karanjit cheema :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

the xml schema that i am using is this::

<interaction_sessions>
       - <interaction_session>
                  <number_of_people_who_viewed>1</number_of_people_who_viewed>
                  <names_of_viewers>,vinod</names_of_viewers>
                   <duration_of_viewing>00:00:07.2240000</duration_of_viewing>
          </interaction_session>
 </interaction_sessions>


the xquery scripts that i am using
are
  • /interaction_sessions
  • //interaction_session
  • /interaction_sessions/names_of_people_who_viewed
none of the above xqueries works until i make them conditional expressions like
/interaction_sessions/names_of_people_who_viewed = '    '

Regards
Karanjit Cheema



On Wed, Nov 4, 2009 at 9:35 PM, Dmitriy Shabanov <shabanovd@...> wrote:
> On Wed, 2009-11-04 at 21:13 +0530, karanjit cheema wrote:
>> any xquery i write in the file gives a hit only when i write in the
>> form of a conditional expression that specifies the search criteria.
>> even if the tags do not exist in my xml file.
>>
>> can some 1 please give a few examples of how to retrieve the data of a
>> specific tag after matching it under certain conditions.
>
> Can you share xquery script?
>
> --
> Cheers,
>
> Dmitriy Shabanov
>
>


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Exist-open mailing list
Exist-open@...
https://lists.sourceforge.net/lists/listinfo/exist-open

Re: Xquery in java embedded database

by Dannes Wessels-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

On 4 Nov 2009, at 16:43 , karanjit cheema wrote:

can some 1 please give a few examples of how to retrieve the data of a
specific tag after matching it under certain conditions.

I really would like to suggest to develop in a different way. Start the interactive client in 'local' mode, and use the query dialog box to write and test your queries. Learn the language. If the queries work there, you can think of moving to get access to data via java code.


Kind regards

Dannes

--
eXist-db Native XML Database - http://exist-db.org









------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Exist-open mailing list
Exist-open@...
https://lists.sourceforge.net/lists/listinfo/exist-open

Re: Xquery in java embedded database

by Dannes Wessels-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

On 4 Nov 2009, at 19:59 , karanjit cheema wrote:

the xquery scripts that i am using 
are 
  • /interaction_sessions
  • //interaction_session
  • /interaction_sessions/names_of_people_who_viewed
none of the above xqueries works until i make them conditional expressions like
/interaction_sessions/names_of_people_who_viewed = '   

'none work' .... do they return nothing, or do they return unexpected results?

Please first  describe what data you want to retrieve from the XML document.  These are three different expressions and would result into 3 different results.
the third 'query' would never result into results
Secondly.... these queries are probably not complete?

Are the XML files actually stored in the database?

again, it is a good idea to play with the interactive client in embedded mode first: bin\client.bat -l

Kind regards

Dannes

--
eXist-db Native XML Database - http://exist-db.org









------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Exist-open mailing list
Exist-open@...
https://lists.sourceforge.net/lists/listinfo/exist-open

Re: Xquery in java embedded database

by karanjit cheema :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

hi
the xqueries return 0 hits for the above given code that i am using.
if i turn them into conditional expressions the number of hits becomes 1 .
i have stored only 1 xml document in the database.

Karanjit Cheema




------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Exist-open mailing list
Exist-open@...
https://lists.sourceforge.net/lists/listinfo/exist-open