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/04/20 11:25:03 UTC
[Bug 1425] New - XPath fails to catch document Element
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=1425
*** shadow/1425 Fri Apr 20 02:25:02 2001
--- shadow/1425.tmp.6547 Fri Apr 20 02:25:02 2001
***************
*** 0 ****
--- 1,99 ----
+ +============================================================================+
+ | XPath fails to catch document Element |
+ +----------------------------------------------------------------------------+
+ | Bug #: 1425 Product: XalanJ2 |
+ | Status: NEW Version: 2.0.1 |
+ | Resolution: Platform: PC |
+ | Severity: Normal OS/Version: |
+ | Priority: Component: org.apache.xpath |
+ +----------------------------------------------------------------------------+
+ | Assigned To: xalan-dev@xml.apache.org |
+ | Reported By: maillist@nue.et-inf.uni-siegen.de |
+ | CC list: Cc: |
+ +----------------------------------------------------------------------------+
+ | URL: |
+ +============================================================================+
+ | DESCRIPTION |
+ Dear Xalan Team
+
+ I get unexpected results if I apply the XPath to the attached sample documents.
+ This affects Xalan 2.0.x
+
+ "(//.)"
+
+ to the XML documents shown below. The problem is that the XPath does not catch
+ the document Element if comments and/or PIs follow the document root. If I
+ modify the XPath to explicitly catch the document Element (everything below
+ document except of comments and PIs):
+
+ "(//. | /*[not(self::processing-instruction() or self::comment())])"
+
+ then it catches the documentElement. To illustrate this behaviour, I modified
+ \xml-xalan\java\samples\ApplyXPath\ApplyXPath.java to be a bit more noisy. The
+ inner part then looks like:
+
+ #### Modified SOURCE #########################
+
+ NodeIterator nl = XPathAPI.selectNodeIterator(doc, xpath);
+ // Serialize the found nodes to System.out.
+ System.out.println("<output>");
+ String[] nodeTypeString = new String[]{
+ "", "ELEMENT", "ATTRIBUTE", "TEXT_NODE",
+ "CDATA_SECTION", "ENTITY_REFERENCE",
+ "ENTITY", "PROCESSING_INSTRUCTION",
+ "COMMENT", "DOCUMENT", "DOCUMENT_TYPE",
+ "DOCUMENT_FRAGMENT", "NOTATION" };
+ int i = 0;
+ Node n;
+ while ((n = nl.nextNode()) != null) {
+ System.out.println("<node" + ++i + " nodeType=\""
+ + nodeTypeString[n.getNodeType()] + "\">");
+ serializer.transform(new DOMSource(n),
+ new StreamResult(System.out));
+ System.out.println("</node" + i + ">");
+ System.out.println();
+ }
+ System.out.println("</output>");
+
+ #### INPUT DATA #########################
+ This input data means 8 simgle documents, each document in a sinle line, a
+ <doc/> element and additional comments/PIs. The first 3 documents miss the
+ documentElement.
+
+ Bad
+ <doc><a /> </doc><!-- --> # mixed content and following comment
+ <doc><a /> </doc><?pi?> # mixed content and following PI
+ <doc><a /><b /></doc><!-- --> # mixed content and following comment
+
+ Good
+ <doc><a /></doc><!-- --> # 'clean' content and following comment
+ <doc><a /> </doc> # mixed content and nothing follows
+ <!-- --><doc><a /> </doc> # mixed content and preceding comment
+ <?pi?><doc><a /> </doc> # mixed content and preceding PI
+ <doc><a /><b /></doc> # mixed ElemContent
+
+ #### SAMPLE OUTPUT #########################
+
+ Input was <doc><a /><b /></doc><!-- -->
+ XPath was (//.)
+ Software was Xerces 1.3.1 and Xalan 2.0.1 on JDK1.3.0 on Windows 2000
+ It catches the <a/> Element, the <b/> Element, the folowing comment and the
+ _DOCUMENT_ node, but not the _ELEMENT_ containing the documentElement.
+
+ OUTPUT:
+ Loading classes, parsing my_input.xml, and setting up serializer
+ Querying DOM using (//.)
+ <output>
+ <node1 nodeType="ELEMENT">
+ <a/></node1>
+
+ <node2 nodeType="ELEMENT">
+ <b/></node2>
+
+ <node3 nodeType="DOCUMENT">
+ <doc><a/><b/></doc></node3>
+
+ <node4 nodeType="COMMENT">
+ </node4>
+
+ </output>