Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4927480

DOMParser implementation calls DOMParserFilter.acceptNode() twice

XMLWordPrintable

    • 1.3
    • sparc
    • solaris_2.6

        Name: apR10229 Date: 09/24/2003


        Filed By : SPB JCK team (###@###.###)
        JDK : java full version "1.5.0-beta-b20"
        JCK : 1.5
        Platform[s] : Solaris
        switch/Mode :
        JCK test owner : http://javaweb.eng/jct/sqe/JCK-tck/usr/owners.jto
        Failing Test [s] : N/A


        Problem description
        ===================
        DOMParser implementation call DOMParserFilter.acceptNode() twice.
        For the following xml source:

        <ROOT><CHILD/></ROOT>

        when we implement DOMParserFilter and set it to a DOMParser,
        implementation of DOMParser call acceptNode() twice for element CHILD.

        This looks like an undefined behavior of DOMParser implementation.
            
        Minimized test:
        ===============
        ------- Test.java -------
        import java.io.*;
        import org.w3c.dom.ls.*;
        import org.w3c.dom.*;
        import javax.xml.parsers.*;
        import org.xml.sax.*;
        import org.w3c.dom.traversal.*;

        public class Test {
            public static void main(String[] argv) {
                String xml = "<ROOT><CHILD/></ROOT>";
                System.out.println("Applying filter to: "+xml);
                DocumentBuilder parser = null;
                Document doc = null;
                try {
                    parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
                    doc = parser.parse(new StringBufferInputStream(xml));
                } catch (Throwable e) {
                    e.printStackTrace();
                }
                DOMImplementationLS implLS = (DOMImplementationLS) doc.getImplementation().getFeature("LS","3.0");
                DOMParser dp = implLS.createDOMParser(DOMImplementationLS.MODE_SYNCHRONOUS,null);
                DOMInput src = implLS.createDOMInput();
                src.setStringData(xml);
                dp.setFilter(
                    new DOMParserFilter() {
                        public short startElement(Element elt) {
        System.out.println("StartElement: "+elt.getTagName());
        return FILTER_ACCEPT;
                        }
                        public short acceptNode(Node enode) {
                            System.out.println("AcceptNode: "+enode.getNodeName());
        return FILTER_ACCEPT;
        }
        public int getWhatToShow() {
        return NodeFilter.SHOW_ALL;
        }
        }
                );
                dp.parse(src);
            }
        }

        ------- end-of-Test.java -------

        Minimized test output:
        ======================
        <pav@hammer(pts/3).258> java Test
        Applying filter to: <ROOT><CHILD/></ROOT>
        StartElement: ROOT
        StartElement: CHILD
        AcceptNode: CHILD
        AcceptNode: CHILD
        AcceptNode: ROOT


        JCK test source location:
        ==========================
        /java/re/jck/1.5/promoted/latest/JCK-runtime-15/tests

        Specific Machine Info:
        =====================
        SunOS orion 5.9 Generic_112233-03 sun4u sparc SUNW,Ultra-Enterprise

        ======================================================================

              rmandavasunw Ramesh Mandava (Inactive)
              pavsunw Pav Pav (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: