You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Scott Severtson <sc...@auragen.com> on 2000/05/15 16:52:36 UTC
Bug with XPath and default namespace
I think I might have stumbled onto a bug in XPathProcessorImpl. While using
some code copied from the "ApplyXPath" (in XPathAPI).java sample to test an
XPath, I run the following exception.
java.lang.StringIndexOutOfBoundsException: -1
at java/lang/String.substring (String.java)
at org/apache/xalan/xpath/XPathProcessorImpl.tokenize
(XPathProcessorImpl.java:430)
at org/apache/xalan/xpath/XPathProcessorImpl.tokenize
(XPathProcessorImpl.java:222)
at org/apache/xalan/xpath/XPathProcessorImpl.initXPath
(XPathProcessorImpl.java:153)
at com/scotty/content/XMLHelper.selectNodeList (XMLHelper.java:45)
at jsp/xpathtest._jspService (xpathtest.java:65)
at com/livesoftware/jsp/HttpJSPServlet.service (HttpJSPServlet.java:29)
at com/livesoftware/jsp/JSPServlet.service (JSPServlet.java:62)
at javax/servlet/http/HttpServlet.service (HttpServlet.java:828)
at com/livesoftware/jrun/JRun.runServlet (JRun.java:305)
at com/livesoftware/jrun/JRunGeneric.handleConnection
(JRunGeneric.java:109)
at
com/livesoftware/jrun/service/proxy/JRunProxyServiceHandler.handleRequest
(JRunProxyServiceHandler.java:131)
at com/livesoftware/jrun/service/ThreadConfigHandler.run
(ThreadConfigHandler.java:96)
This error only occurs when attempting to use an XPath statment against an
XML file with a default namespace. For example:
XPath: ":Bar[@Attrib='1']"
XML:
<?xml version="1.0" ?>
<Foo xmlns="http://www.foo.com">
<Bar Attrib="1">
<Fluff>12345</Fluff>
</Bar>
<Bar Attrib="2">
<Fluff>67890</Fluff>
</Bar>
</Foo>
If I remove the "xmlns="http://www.foo.com"" section, or change it to
"xmlns:foobar="http://www.foo.com"", I can use the XPath "Bar[@Attrib='1']"
successfully. I poked around in the source, and changed line 430 from:
addToTokenQueue(pat.substring(i-1, i+1));
to:
addToTokenQueue(pat.substring((i==0)?0:i-1, i+1));
which then gave a much more meaningful error:
pattern = ':Bar[@Attrib='1']'
Extra illegal tokens: 'Bar', '[', '@', 'Attrib', '=', '"1"', ']'
at org/apache/xalan/xpath/XPathProcessorImpl.error
(XPathProcessorImpl.java)
at org/apache/xalan/xpath/XPathProcessorImpl.error
(XPathProcessorImpl.java)
at org/apache/xalan/xpath/XPathProcessorImpl.initXPath
(XPathProcessorImpl.java)
at com/scotty/content/XMLHelper.selectNodeList (XMLHelper.java:45)
at jsp/xpathtest._jspService (xpathtest.java:65)
at com/livesoftware/jsp/HttpJSPServlet.service (HttpJSPServlet.java:29)
at com/livesoftware/jsp/JSPServlet.service (JSPServlet.java:62)
at javax/servlet/http/HttpServlet.service (HttpServlet.java:828)
at com/livesoftware/jrun/JRun.runServlet (JRun.java:305)
at com/livesoftware/jrun/JRunGeneric.handleConnection
(JRunGeneric.java:109)
at
com/livesoftware/jrun/service/proxy/JRunProxyServiceHandler.handleRequest
(JRunProxyServiceHandler.java:131)
at com/livesoftware/jrun/service/ThreadConfigHandler.run
(ThreadConfigHandler.java:96)
The problem seems to be starting an XPath with a blank namespace argument,
i.e. ":Anything".
I hope I've given you enough information to track it down, but please email
me with any questions.
Thanks!
Scott Severtson scotty@auragen.com
Applications Developer (716) 442-0840
Auragen Communications Rochester, NY