You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by bu...@apache.org on 2001/03/26 09:08:37 UTC

[Bug 1110] New - XPath module returns a curious result

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=1110

*** shadow/1110	Sun Mar 25 23:08:36 2001
--- shadow/1110.tmp.12057	Sun Mar 25 23:08:36 2001
***************
*** 0 ****
--- 1,58 ----
+ +============================================================================+
+ | XPath module returns a curious result                                      |
+ +----------------------------------------------------------------------------+
+ |        Bug #: 1110                        Product: XalanJ2                 |
+ |       Status: NEW                         Version: 2.0.1                   |
+ |   Resolution:                            Platform: PC                      |
+ |     Severity: Major                    OS/Version:                         |
+ |     Priority:                           Component: org.apache.xpath        |
+ +----------------------------------------------------------------------------+
+ |  Assigned To: xalan-dev@xml.apache.org                                     |
+ |  Reported By: kent@hauN.org                                                |
+ |      CC list: Cc:                                                          |
+ +----------------------------------------------------------------------------+
+ |          URL:                                                              |
+ +============================================================================+
+ |                              DESCRIPTION                                   |
+ I expect the following program prints " e1\n null\n".
+ But it actually prints " null\n e1\n".
+ 
+ import java.io.StringReader;
+ import org.apache.xerces.parsers.DOMParser;
+ import org.apache.xpath.XPath;
+ import org.apache.xpath.XPathAPI;
+ import org.apache.xpath.objects.XObject;
+ import org.w3c.dom.Document;
+ import org.w3c.dom.Node;
+ import org.w3c.dom.traversal.NodeIterator;
+ import org.xml.sax.InputSource;
+ 
+ public class Bug {
+     public static void main(String[] argv) throws Exception {
+         DOMParser domp = new DOMParser();
+         domp.parse(new InputSource(new StringReader(
+ "<!DOCTYPE doc []>\n"
+ +"<doc>\n"
+ +"   <e1>\n"
+ +"      <e2/>\n"
+ +"   </e1>\n"
+ +"</doc>\n"
+ )));
+         Document doc = domp.getDocument();
+ 
+         XObject xobj = XPathAPI.eval(doc, "(//.)[self::e1]");
+         if (xobj.getType() != XObject.CLASS_NODESET) {
+             System.err.println(xobj.str());
+         } else {
+             NodeIterator iter = xobj.nodeset();
+             System.err.println("Class: "+iter.getClass().getName());
+             Node n = iter.nextNode();
+             System.err.println(n == null ? " null" : " "+n.getNodeName());
+             n = iter.nextNode();
+             System.err.println(n == null ? " null" : " "+n.getNodeName());
+             while ((n = iter.nextNode()) != null)
+                 System.err.println(" "+n.getNodeName());
+             iter.detach();
+         }
+     }
+ }

Question Re: [Bug 1110] New - XPath module returns a curious result

Posted by James Melton <ja...@cylogix.com>.
I have looked into the W3 docs on XML and and XPath but can't convince
myself of the right way to evaluate this XPath, (//.)[self::e1]  Is it
legitimate?

This bug does not appear if you use (//)[self::e1]  and an error results
from //.[self::e1]  Both of those results make sense to me. 

On the stranger side, there appears to be no problem getting the
anticipated result from the original XPath if you exclude the document's
DTD. Of course I can't tell what the DTD implies as written. It doesn't
seem to say anything about the structure of the document.

Any ideas?

Jim.

bugzilla@apache.org wrote:

> + "<!DOCTYPE doc []>\n"
> + +"<doc>\n"
> + +"   <e1>\n"
> + +"      <e2/>\n"
> + +"   </e1>\n"
> + +"</doc>\n"

> +         XObject xobj = XPathAPI.eval(doc, "(//.)[self::e1]");

____________________________________________________________
James Melton                 CyLogix
609.750.5190                 609.750.5100
james.melton@cylogix.com     www.cylogix.com