You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by "Henry Zongaro (JIRA)" <xa...@xml.apache.org> on 2005/06/08 15:41:16 UTC

[jira] Resolved: (XALANJ-2138) String literals passed to XPathAPI result in XPathException

     [ http://issues.apache.org/jira/browse/XALANJ-2138?page=all ]
     
Henry Zongaro resolved XALANJ-2138:
-----------------------------------

    Resolution: Invalid

I'm inclined to view this as invalid.  Although the XPath expression that you're evaluating is a valid expression, strings, numbers and booleans in XPath cannot be converted to a node or node sets.

The existing behaviour of the Xalan-J XPath API is consistent with other XPath APIs.  For instance, the DOM L3 XPath API [1] allows for TYPE_ERR XPathExceptions to be thrown if the result of evaluating an XPath expression cannot be converted to the requested result type.  Similarly, the JAXP 1.3 XPath API states, "Conversion [of the result] to the [requested] return type follows XPath conversion rules," which implies an error would result if a string literal was evaluated with a requested return type of NODE or NODESET.

If you need to evaluate XPath expressions that might return values of type boolean, number or string, I suggest you use the XPathAPI.eval methods.

If you disagree, please feel free to reopen this bug report.

[1] http://www.w3.org/TR/2004/NOTE-DOM-Level-3-XPath-20040226/xpath.html#XPathEvaluator-evaluate

> String literals passed to XPathAPI result in XPathException
> -----------------------------------------------------------
>
>          Key: XALANJ-2138
>          URL: http://issues.apache.org/jira/browse/XALANJ-2138
>      Project: XalanJ2
>         Type: Bug
>   Components: XPath-API
>     Versions: 2.6
>  Environment: WinXP sp2 Prof, J2SDK1.4.2_08, Eclipse 3.1Mx, Xalan 2.6.0
>     Reporter: Ian Sollars

>
> The following is a valid XPath expression:
> 'test'
> However, code such as the following:
> 		Document d = XMLUtils.newDocument(new StringInputStream("<xml></xml>"));
> 		
> 		System.out.println(  XPathAPI.selectSingleNode(d.getDocumentElement(), "'test'")  );
> produces the following stack trace:
> org.apache.xpath.XPathException: Can not convert #STRING to a NodeList!
> 	at org.apache.xpath.objects.XObject.error(XObject.java:741)
> 	at org.apache.xpath.objects.XObject.nodeset(XObject.java:471)
> 	at org.apache.xpath.XPathAPI.selectNodeIterator(XPathAPI.java:175)
> 	at org.apache.xpath.XPathAPI.selectSingleNode(XPathAPI.java:133)
> 	at org.apache.xpath.XPathAPI.selectSingleNode(XPathAPI.java:113)
> [jUnit & Eclipse lines elided]
> My suggestion is to change XPathAPI.selectNodeIterator (line 166 in 2.6.0) to test getType() against CLASS_STRING and CLASS_NUMBER(?), and return contextNode.getOwnerDocument().createTextNode(list.str()) if equal to one of those two.
> Thanks a lot,
>  - Ian

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-dev-help@xml.apache.org