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

normalizeDocument() does not normalize values

    Details

    • Subcomponent:
    • Resolved In Build:
      1.3
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Backports

        Description

        Name: erR10175 Date: 05/25/2004



         The following method in the class org.w3c.dom.Document

        void normalizeDocument()

        does not normalize values when the following DOMConfiguration properties are set:
        schema-type, schema-location, validate, datatype-normalization, error-handler.

        The javadoc of the DOMConfiguration class reads:
        "
         'datatype-normalization'
            true
                [optional] Expose schema normalized values in the tree, such as XML Schema
                normalized values in the case of XML Schema. Since this parameter requires
                to have schema information, the "validate" parameter will also be set to true.
                Having this parameter activated when "validate" is false has no effect and
                no schema-normalization will happen.
        "

        So the sample (see below) expects the string '\t\r\n 1 ' to be normalized to '1'.

        The bug is found in jdk1.5.0/beta2/b51 when the fix of the bug #5041848 is integrated:

        5041848 normalizeDocument() does not perform validation

        The bug affects the following new JCK-15 beta2 test:

          api/org_w3c/dom/DOMConfiguration/index.html#Params[DatatypeNormalization001]

        To reproduce the bug compile and run the following code as shown in the log below.
        ---------------------------- test.xsd
        <?xml version="1.0"?>
        <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                    targetNamespace="test">
            <xsd:element name="root" type="xsd:int"/>
        </xsd:schema>
        -------------------------------------

        --------------------------- test.java
        import org.w3c.dom.DOMError;
        import org.w3c.dom.DOMErrorHandler;
        import org.w3c.dom.Document;
        import org.w3c.dom.Element;
        import org.w3c.dom.Node;
        import org.w3c.dom.DOMConfiguration;
        import javax.xml.parsers.DocumentBuilderFactory;
        import javax.xml.XMLConstants;

        class test {

            static class TestHandler implements DOMErrorHandler {
                public boolean handleError(DOMError error) {
                    if (error.getSeverity() == DOMError.SEVERITY_ERROR
                     || error.getSeverity() == DOMError.SEVERITY_FATAL_ERROR) {
                        throw new RuntimeException(error.getMessage());
                    }
                    return true;
                }
            }

            public static void main(String [] args) throws Exception {
                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                dbf.setNamespaceAware(true);
                dbf.setValidating(true);

                Document doc = dbf.newDocumentBuilder()
                                  .getDOMImplementation()
                                  .createDocument("test", "ns:root", null);

                DOMConfiguration config = doc.getDomConfig();
                config.setParameter("schema-type", XMLConstants.W3C_XML_SCHEMA_NS_URI);
                config.setParameter("schema-location", "test.xsd");
                config.setParameter("validate", Boolean.TRUE);
                config.setParameter("datatype-normalization", Boolean.TRUE);
                TestHandler testHandler = new TestHandler();
                config.setParameter("error-handler", testHandler);

                Element root = doc.getDocumentElement();
                root.appendChild(doc.createTextNode("\t\r\n 1 "));

                doc.normalizeDocument();
                Node child = root.getFirstChild();
                if (child == null
                 || child.getNodeType() != Node.TEXT_NODE
                 || !"1".equals(child.getNodeValue())) {
                    System.out.println("Failed: child: " + child
                                     + ", expected: text node '1'");
                } else {
                    System.out.println("Passed.");
                }
            }
        }
        -------------------------------------

        --------------------------------- log
        $javac test.java && java -showversion test
        java version "1.5.0-beta2"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b51)
        Java HotSpot(TM) Client VM (build 1.5.0-beta2-b51, mixed mode)

        Failed: child: [#text:
         1 ], expected: text node '1'
        -------------------------------------

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

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  vkorcl Venugopal K (Inactive)
                  Reporter:
                  reysunw Rey Rey (Inactive)
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  0 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: