You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by "Ian Sollars (JIRA)" <xa...@xml.apache.org> on 2005/06/03 13:49:57 UTC

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

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


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

Posted by "Ian Sollars (JIRA)" <xa...@xml.apache.org>.
    [ http://issues.apache.org/jira/browse/XALANJ-2138?page=comments#action_67004 ] 

Ian Sollars commented on XALANJ-2138:
-------------------------------------

This is my quick and dirty fix to XPathAPI.selectNodeIterator(). I imagine for the actual fix that you wouldn't resort to using an anonymous inner class.

Regards,

 - Ian

  /**
   *  Use an XPath string to select a nodelist.
   *  XPath namespace prefixes are resolved from the namespaceNode.
   *
   *  @param contextNode The node to start searching from.
   *  @param str A valid XPath string.
   *  @param namespaceNode The node from which prefixes in the XPath will be resolved to namespaces.
   *  @return A NodeIterator, should never be null.
   *
   * @throws TransformerException
   */
  public static NodeIterator selectNodeIterator(
          final Node contextNode, String str, Node namespaceNode)
            throws TransformerException
  {

    // Execute the XPath, and have it return the result
    final XObject list = eval(contextNode, str, namespaceNode);
	
	if( list.getType() == XObject.CLASS_NUMBER ||
		list.getType() == XObject.CLASS_STRING ) {
			return new NodeIterator() {
				
				private Node textNode = contextNode.getOwnerDocument().createTextNode(list.str());

				public int getWhatToShow() {
					return NodeFilter.SHOW_TEXT;
				}

				public void detach() {
					textNode = null;					
				}

				public boolean getExpandEntityReferences() {
					return false;
				}

				public Node getRoot() {
					return null;
				}

				public Node nextNode() throws DOMException {
					Node result = textNode;
					textNode = null;
					return result;
				}

				public Node previousNode() throws DOMException {
					return null;
				}

				public NodeFilter getFilter() {
					return null;
				}
				
			};
	}
		

    // Have the XObject return its result as a NodeSetDTM.                
    return list.nodeset();
  }


> 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


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

Posted by "Brian Minchau (JIRA)" <xa...@xml.apache.org>.
     [ http://issues.apache.org/jira/browse/XALANJ-2138?page=all ]

Brian Minchau updated XALANJ-2138:
----------------------------------

    Fix Version: 2.7

> 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
>      Fix For: 2.7

>
> 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


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

Posted by "Henry Zongaro (JIRA)" <xa...@xml.apache.org>.
     [ 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


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

Posted by "Brian Minchau (JIRA)" <xa...@xml.apache.org>.
    [ http://issues.apache.org/jira/browse/XALANJ-2138?page=comments#action_12312965 ] 

Brian Minchau commented on XALANJ-2138:
---------------------------------------

The concept of casting a string, number or boolean to a node is not permitted in XPath itself, so we aren't sure why the XPathAPI should permit it.

Henry Z. may provide further comments on this. However it doesn't look like a legitimate problem.

> 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