[ 
https://issues.apache.org/jira/browse/JXPATH-12?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12630238#action_12630238
 ] 

Murty Gurajada commented on JXPATH-12:
--------------------------------------

The fix that is in JXPath 1.3 appears to solve only part of the problem. When 
the context node supplied to JXPath is a Document, the evaluation of the XPath 
correctly returns the expected data. However, if the context node is an 
Element, the xpath expression does not evaluate correctly. Specifically, the 
behavior in JXPath 1.3 does not appear to be consistent with javax.xml.xpath in 
Java 1.5 as well as the text in XPath 1.0 specification.

>From the Xpath specification at:

http://www.w3.org/TR/xpath

descendant-or-self::para selects the para element descendants of the context 
node and, if the context node is a para element, the context node as well

Section '2.5 Abbreviated Syntax' clarifies with an example:

//para selects all the para descendants of the document root and thus selects 
all para elements in the same document as the context node

Please see the attached zip file (xpathEvalBug.zip) containing a package with 
the JUnit test org.apache.commons.jxpath.test.TestDescOrSelfEval.java that I 
ran in Java 1.5.

I have used the same xml fragment used in the bug report:

<root id='1234'/>

The class contains 4 tests:

1. testJXPathDescOrSelfWithDoc() throws Exception tests JXPath evaluation of a 
descendant-or-self ('//') expression on a Document context

This test returns the expected data in JXPath 1.3 whereas it used to fail in 
JXPath 1.2.


2. testJXPathDescOrSelfWithEl() throws Exception tests JXPath evaluation of a 
descendant-or-self ('//') expression on an Element context (for 'root')

This test does not return the expected data in JXPath 1.3. It also used to fail 
in JXPath 1.2.

3. testXPathDescOrSelfWithDoc() tests javax.xml.xpath evaluation of a 
descendant-or-self ('//') expression on a Document context

This test returns the expected data.

4. testXPathDescOrSelfWithEl() tests javax.xml.xpath evaluation of a 
descendant-or-self ('//') expression on an Element context (for 'root')

This test returns the expected data.

If you run the attached JUnit test in java 1.5, the javax.xml.xpath 
implementation returns data consistent with the text of the specification. I 
really want to use JXPath in my project because some tests I ran show it is 
much faster than javax.xml.xpath. However, this issue is preventing me from 
migrating to JXPath. Is it possible to fix this issue? If yes, how soon would 
it be available for download?

 



> Descendant or self axis does not work correctly at root node
> ------------------------------------------------------------
>
>                 Key: JXPATH-12
>                 URL: https://issues.apache.org/jira/browse/JXPATH-12
>             Project: Commons JXPath
>          Issue Type: Bug
>    Affects Versions: 1.2 Final
>         Environment: Operating System: other
> Platform: Other
>            Reporter: Simon Raess
>             Fix For: 1.3
>
>         Attachments: DescendantOrSelfTest.java, patch.jxpath-12.txt
>
>
> Given the following XML document: <root id="1234"/>
> and the XPath: //root/@id/text().
> JXPath returns null instead of "1234".
> JXPathContext context = JXPathContext.newContext(doc);
> assertEquals(value, context.selectSingleNode("//root/@id/text()"));
> The attached JUnit test highlights the problem. It seems that JXPath does not
> find the root node if it is accessed with the axis descendant-or-self.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to