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

Document.normalizeDocument() does not provide [element content whitespace]

    XMLWordPrintable

    Details

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

      Description

      Name: erR10175 Date: 04/16/2004



           The method org.w3c.dom.Document.normalizeDocument() does not provide
      the [element content whitespace] attribute for text nodes containing white space
      characters within element content.

      The javadoc of the method org.w3c.dom.Text.isElementContentWhitespace() reads:
      "
      The text node is determined to contain whitespace in element content during the load
      of the document or if validation occurs while using Document.normalizeDocument().
      "

      So the RI is expected to return true for characters '\t\n\r ' after the document
      is normalized with validation turned on (see the test.java below).

      This bug affects new test in JCK 1.5

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

      The test is currently in the kfl with the RI bug:

      4963562 DOMConfiguration: some required Document configuration properties are not supported

      The bug is found in jdk1.5.0/beta/b47.

      To reproduce the bug compile and run test.java as shown in the log below:
      ------------------------------------------ test.java
      import java.io.StringReader;
      import org.xml.sax.InputSource;
      import org.w3c.dom.DOMImplementation;
      import org.w3c.dom.DOMConfiguration;
      import org.w3c.dom.Document;
      import org.w3c.dom.Element;
      import org.w3c.dom.Node;
      import org.w3c.dom.Text;
      import javax.xml.parsers.DocumentBuilder;
      import javax.xml.parsers.DocumentBuilderFactory;

      class test {

          private static void exit(int code, String msg) {
              System.out.println( (code == 0 ? "Passed: ":"Failed: ") + msg);
              System.exit(code);
          }

          static final String test1_xml =
              "<?xml version=\"1.0\"?>\n"
              +"<!DOCTYPE root [\n"
              +" ELEMENT root (elem+)\n"
              +" ELEMENT elem EMPTY\n"
              +"]>\n"
              +"<root> <elem/></root>\n";

          public static void main(String [] args) throws Exception {

              DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
              dbf.setValidating(true);
              dbf.setNamespace(true);
              DocumentBuilder parser = dbf.newDocumentBuilder();

              InputSource inSource = new InputSource(new StringReader(test1_xml));
              Document doc = parser.parse(inSource);

              Element root = doc.getDocumentElement();

              Node firstChild = root.getFirstChild();
              Text text = doc.createTextNode("\t\n\r ");
              root.replaceChild(text, firstChild);

              DOMConfiguration config = doc.getDomConfig();
              config.setParameter("element-content-whitespace", Boolean.TRUE);
              config.setParameter("validate", Boolean.TRUE);

              doc.normalizeDocument();

              firstChild = root.getFirstChild();
              if (firstChild == null
               || firstChild.getNodeType() != Node.TEXT_NODE
               || !((Text)firstChild).isElementContentWhitespace()) {
                  exit(1, "the first child is " + firstChild
                  + ", expected a text node with the four whitespace characters");
              }

              exit(0, "OK");
          }
      }
      ----------------------------------------------------

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

      Failed: the first child is [#text:
       ], expected a text node with the four whitespace characters
      ----------------------------------------------------

      ======================================================================
      ###@###.### 2004-04-19
      ###@###.### 2004-04-21

        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: