Bug 22155 - Support XPath queries that return objects other than node sets.
Summary: Support XPath queries that return objects other than node sets.
Alias: None
Product: Xindice
Classification: Unclassified
Component: XPath (show other bugs)
Version: cvs head (1.1)
Hardware: Other other
: P3 enhancement
Target Milestone: ---
Assignee: Xindice Developers
Depends on:
Reported: 2003-08-06 04:04 UTC by Kevin O'Neill
Modified: 2004-11-16 19:05 UTC (History)
1 user (show)


Note You need to log in before you can comment on or make changes to this bug.
Description Kevin O'Neill 2003-08-06 04:04:32 UTC
Any xpath expression that returns anything but a nodeset will fail.
For example these three queries all result in exception.

string(//person[first='John' and last='Smith']/first)
count(//person[first='John' and last='Smith'])

To support this the we will need to update the NodeSet implementation to support
other datatypes.

I've added unit tests to the test suite that expose this problem
Comment 1 Vadim Gritsenko 2004-03-04 13:23:34 UTC
Fixed, Closed.
Comment 2 Yogesh 2004-03-05 22:51:25 UTC
Problem in XPathQueryResolver.ResultSet.prepareNextNode() when iterating over 
Collection and empty document i.e. '<?xml version="1.0" encoding="UTF-8"?>' is 
returned. Then the node returned by the document is null and a an exception is 
thrown at xp.execute(xpc, n, pfx) -- (exception attached at end). Checking for 
node != null fixes this problem. I'm not sure though how the empty document go 
into the DB in the first place.

DBDocument d = (DBDocument) context.getDocument(keySet[keyPos++]);
// dom2str(d) == "<?xml version="1.0" encoding="UTF-8"?>"
if (d == null) {
Node n = d.getDocumentElement();
// n == null
if(n == null) continue; // added to fix the problem

Exception thrown by xp.execute(xpc, n, pfx):
java.lang.IllegalArgumentException: Node must be non-null for 
	at org.apache.xml.dtm.ref.DTMManagerDefault.getDTMHandleFromNode
	at org.apache.xpath.XPathContext.getDTMHandleFromNode
	at org.apache.xpath.XPath.execute(XPath.java:274)
	at org.apache.xindice.core.query.QueryUtil.queryResultsToDOM
	at org.apache.xindice.core.query.QueryUtil.queryResultsToDOM
	at org.apache.xindice.client.xmldb.embed.CollectionImpl.query
	at org.apache.xindice.client.xmldb.XindiceCollection.query
	at org.apache.xindice.client.xmldb.services.QueryService.query
	at edu.indiana.extreme.gsx.util.XindiceUtil.executeXPath


Comment 3 Vadim Gritsenko 2004-03-05 23:39:24 UTC
Thanks for your observation. Can you also turn on DEBUG and see may be there are
some ignored exceptions preceding this?
Comment 4 Vadim Gritsenko 2004-03-20 13:48:55 UTC
Yogesh, any updates?
Comment 5 Vadim Gritsenko 2004-05-21 12:48:21 UTC
Added test for null getDocumentElement() with log statement.