You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xindice-users@xml.apache.org by Peter Charles <pe...@SIMS.Berkeley.EDU> on 2004/03/04 00:59:19 UTC

Query Results

Hello,

I have some questions about the query behavior

I created a collection food and put the following documents into it.

<food type="snack">
	<dish num="1">apple</dish>
	<dish num="2">snickers</dish>
	<dish num="3">crackers</dish>
	<dish num="4">carrots</dish>
</food>
<food type="lunch">
	<dish num="1">spagetti</dish>
	<dish num="2">steak</dish>
	<dish num="3">macroni and cheese</dish>
	<dish num="4">stir fry</dish>
</food>
<food type="breakfast">
	<dish num="1">Toast</dish>
	<dish num="2">Omelet </dish>
	<dish num="3">Cereal</dish>
	<dish num="4">Bagel</dish>
</food>
<food type="lunch">
	<dish num="1">sandwich</dish>
	<dish num="2">pho</dish>
	<dish num="3">pizza</dish>
	<dish num="4">leftovers</dish>
</food>

if I use the following query I get the expected result:

xindice xpath_query -c /db/food -q"/food[@type='snack']"
trying to register database

<food src:col="/db/food" src:key="food4.xml" type="snack"
xmlns:src="http://xml.apache.org/xindice/Query">
        <dish num="1">apple</dish>
        <dish num="2">snickers</dish>
        <dish num="3">crackers</dish>
        <dish num="4">carrots</dish>
</food>

if I do the following query I get the expected results.

C:\Documents and Settings\peter>xindice xpath_query -c /db/food -q
"/food/dish[@num='2']"

trying to register database
<dish num="2" src:col="/db/food" src:key="food1.xml"
xmlns:src="http://xml.apache.org/xindice/Query">pho</dish>
<dish num="2" src:col="/db/food" src:key="food2.xml"
xmlns:src="http://xml.apache.org/xindice/Query">Omelet </dish>
<dish num="2" src:col="/db/food" src:key="food3.xml"
xmlns:src="http://xml.apache.org/xindice/Query">steak</dish>
<dish num="2" src:col="/db/food" src:key="food4.xml"
xmlns:src="http://xml.apache.org/xindice/Query">snickers</dish>

but if I do the following query:

xindice xpath_query -c /db/food -q "/food/dish/.='pho'"

trying to register database
<xq:result
xmlns:xq="http://xml.apache.org/xindice/Query">true</xq:result>
<xq:result
xmlns:xq="http://xml.apache.org/xindice/Query">false</xq:result>
<xq:result
xmlns:xq="http://xml.apache.org/xindice/Query">false</xq:result>
<xq:result
xmlns:xq="http://xml.apache.org/xindice/Query">false</xq:result>

I get a result that tells me that there is a <dish>pho</dish> in my
collection, but gives me no information about what document it is in,
which seems strange.

I understand the different nature of these XPath expressions, however
the query seem a natural one, but the result is not particularly useful.

Is this just a limitation of the command line tool?

I'm going to start working with the API now :)

Peter 









-----<CDE/>-----
Center for Document Engineering
University of California, Berkeley
cde.berkeley.edu



Re: Query Results

Posted by Vadim Gritsenko <va...@reverycodes.com>.
Peter Charles wrote:

>One question.
>
>It seems that the results from xpath_query are retuned as a set of xml
>results, is there a design reason why queries don't return an valid xml
>document?
>  
>

Reason is in API, org.xmldb.api.modules.XPathQueryService:

   /**
    * Run an XPath query against the <code>Collection</code>. The XPath 
will be
    * applied to all XML resources stored in the <code>Collection</code>.
    * The result is a
    * <code>ResourceSet</code> containing the results of the query. Any
    * namespaces used in the <code>query</code> string will be evaluated 
using
    * the mappings setup using <code>setNamespace</code>.
    *
    * @param query The XPath query string to use.
    * @return A <code>ResourceSet</code> containing the results of the 
query.
    * @exception XMLDBException with expected error codes.<br />
    *  <code>ErrorCodes.VENDOR_ERROR</code> for any vendor
    *  specific errors that occur.<br />
    */
   ResourceSet query( String query ) throws XMLDBException;


Vadim


RE: Query Results

Posted by Peter Charles <pe...@SIMS.Berkeley.EDU>.
One question.

It seems that the results from xpath_query are retuned as a set of xml
results, is there a design reason why queries don't return an valid xml
document?

Something like this:

<resultSet>
	<dish num="2" src:col="/db/food" src:key="food1.xml"
xmlns:src="http://xml.apache.org/xindice/Query">pho</dish>
	<dish num="2" src:col="/db/food" src:key="food2.xml"
xmlns:src="http://xml.apache.org/xindice/Query">Omelet </dish>
	<dish num="2" src:col="/db/food" src:key="food3.xml"
xmlns:src="http://xml.apache.org/xindice/Query">steak</dish>
	<dish num="2" src:col="/db/food" src:key="food4.xml"
xmlns:src="http://xml.apache.org/xindice/Query">snickers</dish>
</resultSet>

It would be nice as one could then easily access the contents of the
document using DOM.

Thanks

Peter



-----Original Message-----
From: Vadim Gritsenko [mailto:vadim@reverycodes.com] 
Sent: Wednesday, March 03, 2004 6:24 PM
To: xindice-users@xml.apache.org
Subject: Re: Query Results

Peter Charles wrote:

>Hello,
>
>I have some questions about the query behavior
>
>I created a collection food and put the following documents into it.
>
><food type="snack">
>	<dish num="1">apple</dish>
>	<dish num="2">snickers</dish>
>	<dish num="3">crackers</dish>
>	<dish num="4">carrots</dish>
></food>
><food type="lunch">
>	<dish num="1">spagetti</dish>
>	<dish num="2">steak</dish>
>	<dish num="3">macroni and cheese</dish>
>	<dish num="4">stir fry</dish>
></food>
><food type="breakfast">
>	<dish num="1">Toast</dish>
>	<dish num="2">Omelet </dish>
>	<dish num="3">Cereal</dish>
>	<dish num="4">Bagel</dish>
></food>
><food type="lunch">
>	<dish num="1">sandwich</dish>
>	<dish num="2">pho</dish>
>	<dish num="3">pizza</dish>
>	<dish num="4">leftovers</dish>
></food>
>
>if I use the following query I get the expected result:
>
>xindice xpath_query -c /db/food -q"/food[@type='snack']"
>trying to register database
>
><food src:col="/db/food" src:key="food4.xml" type="snack"
>xmlns:src="http://xml.apache.org/xindice/Query">
>        <dish num="1">apple</dish>
>        <dish num="2">snickers</dish>
>        <dish num="3">crackers</dish>
>        <dish num="4">carrots</dish>
></food>
>
>if I do the following query I get the expected results.
>
>C:\Documents and Settings\peter>xindice xpath_query -c /db/food -q
>"/food/dish[@num='2']"
>
>trying to register database
><dish num="2" src:col="/db/food" src:key="food1.xml"
>xmlns:src="http://xml.apache.org/xindice/Query">pho</dish>
><dish num="2" src:col="/db/food" src:key="food2.xml"
>xmlns:src="http://xml.apache.org/xindice/Query">Omelet </dish>
><dish num="2" src:col="/db/food" src:key="food3.xml"
>xmlns:src="http://xml.apache.org/xindice/Query">steak</dish>
><dish num="2" src:col="/db/food" src:key="food4.xml"
>xmlns:src="http://xml.apache.org/xindice/Query">snickers</dish>
>
>but if I do the following query:
>
>xindice xpath_query -c /db/food -q "/food/dish/.='pho'"
>
>trying to register database
><xq:result
>xmlns:xq="http://xml.apache.org/xindice/Query">true</xq:result>
><xq:result
>xmlns:xq="http://xml.apache.org/xindice/Query">false</xq:result>
><xq:result
>xmlns:xq="http://xml.apache.org/xindice/Query">false</xq:result>
><xq:result
>xmlns:xq="http://xml.apache.org/xindice/Query">false</xq:result>
>
>I get a result that tells me that there is a <dish>pho</dish> in my
>collection, but gives me no information about what document it is in,
>which seems strange.
>
>I understand the different nature of these XPath expressions, however
>the query seem a natural one, but the result is not particularly
useful.
>
>Is this just a limitation of the command line tool?
>
>I'm going to start working with the API now :)
>  
>

I have a patch sitting on my drive fixing this issue, but I've not yet 
committed yet... I'll fix this before monday. Somebody also needs to 
write something up on the behavior of different xpath queries in the 
xindice... Wiki page "XPathQuery" sounds like appropriate place... Any 
takers? :-)

Vadim


Re: Query Results

Posted by Vadim Gritsenko <va...@reverycodes.com>.
Peter Charles wrote:

>Hello,
>
>I have some questions about the query behavior
>
>I created a collection food and put the following documents into it.
>
><food type="snack">
>	<dish num="1">apple</dish>
>	<dish num="2">snickers</dish>
>	<dish num="3">crackers</dish>
>	<dish num="4">carrots</dish>
></food>
><food type="lunch">
>	<dish num="1">spagetti</dish>
>	<dish num="2">steak</dish>
>	<dish num="3">macroni and cheese</dish>
>	<dish num="4">stir fry</dish>
></food>
><food type="breakfast">
>	<dish num="1">Toast</dish>
>	<dish num="2">Omelet </dish>
>	<dish num="3">Cereal</dish>
>	<dish num="4">Bagel</dish>
></food>
><food type="lunch">
>	<dish num="1">sandwich</dish>
>	<dish num="2">pho</dish>
>	<dish num="3">pizza</dish>
>	<dish num="4">leftovers</dish>
></food>
>
>if I use the following query I get the expected result:
>
>xindice xpath_query -c /db/food -q"/food[@type='snack']"
>trying to register database
>
><food src:col="/db/food" src:key="food4.xml" type="snack"
>xmlns:src="http://xml.apache.org/xindice/Query">
>        <dish num="1">apple</dish>
>        <dish num="2">snickers</dish>
>        <dish num="3">crackers</dish>
>        <dish num="4">carrots</dish>
></food>
>
>if I do the following query I get the expected results.
>
>C:\Documents and Settings\peter>xindice xpath_query -c /db/food -q
>"/food/dish[@num='2']"
>
>trying to register database
><dish num="2" src:col="/db/food" src:key="food1.xml"
>xmlns:src="http://xml.apache.org/xindice/Query">pho</dish>
><dish num="2" src:col="/db/food" src:key="food2.xml"
>xmlns:src="http://xml.apache.org/xindice/Query">Omelet </dish>
><dish num="2" src:col="/db/food" src:key="food3.xml"
>xmlns:src="http://xml.apache.org/xindice/Query">steak</dish>
><dish num="2" src:col="/db/food" src:key="food4.xml"
>xmlns:src="http://xml.apache.org/xindice/Query">snickers</dish>
>
>but if I do the following query:
>
>xindice xpath_query -c /db/food -q "/food/dish/.='pho'"
>
>trying to register database
><xq:result
>xmlns:xq="http://xml.apache.org/xindice/Query">true</xq:result>
><xq:result
>xmlns:xq="http://xml.apache.org/xindice/Query">false</xq:result>
><xq:result
>xmlns:xq="http://xml.apache.org/xindice/Query">false</xq:result>
><xq:result
>xmlns:xq="http://xml.apache.org/xindice/Query">false</xq:result>
>
>I get a result that tells me that there is a <dish>pho</dish> in my
>collection, but gives me no information about what document it is in,
>which seems strange.
>
>I understand the different nature of these XPath expressions, however
>the query seem a natural one, but the result is not particularly useful.
>
>Is this just a limitation of the command line tool?
>
>I'm going to start working with the API now :)
>  
>

I have a patch sitting on my drive fixing this issue, but I've not yet 
committed yet... I'll fix this before monday. Somebody also needs to 
write something up on the behavior of different xpath queries in the 
xindice... Wiki page "XPathQuery" sounds like appropriate place... Any 
takers? :-)

Vadim