getCount() function usage ?

I tried to use getCount() method of Class TXMLObjectIterator. However, I always got the result of “-1”. I would like to know what will be the actual usage of this method.

I just want to output the total count of the result return.

Some portion of my code is shown below:


response = accessor.xquery(TXQuery.newInstance(“input()/document”, 10);
TXMLObjectIterator iterator = response.getXMLObjectIterator();
int count = iterator.getCount();

System.out.println(“count:” + count);



Please help.

A count is only available, if the method hasCount() returns true. So you should check this upfront. Please check the Javadoc of getCount() and hasCount() for more details.

Generally with XQuery, you will not get a count, because it is not contained in the answer from Tamino.
With X-Query you get a count, if one is available (meaning can be calculated by Tamino on the fly). If this is not the case, you have to query for the count explicetly. In X-Query the query would be:
“count(/document)”.
I don’t know the syntax in XQuery to retrieve the same value. Maybe somebody else can help here…

The Javadoc is not written very clear. Let me summarize the
actual facts:
1. Both hasCount() & getCount() only work for X-Query
2. hasCount() give “true” only for X-Query with cursor i.e. _xql=(query,5)
3. getCount() is very strange. For _xql=(query,5), getCount() returns total
query count but not 5.

I expect getCount() function will be available for XQuery in next version
as well.
API Doc is better written.

Hi Toni,

> The Javadoc is not written very clear.
That might be true in the sense that it doesn’t point out the difference between XQuery and X-Query. The rest is ok, but could probably be made better.

> Let me summarize the actual facts:
> 1. Both hasCount() & getCount() only work for X-Query
Not true. hasCount() works for XQuery (it always indicates that no count is available).

> 2. hasCount() give “true” only for X-Query with cursor i.e. _xql=(query,5)
True.

> 3. getCount() is very strange. For _xql=(query,5), getCount() returns total query count but not 5.
Count is an information calculated by the Tamino XML Server. It always is the total count of the query result (see Javadoc).

> I expect getCount() function will be available for XQuery in next version as well.
Sorry, this is currently not planned.

> API Doc is better written.
Yes, we definitivly need to clarify the explanation.

Best regards,
Christian Gengenbach.