Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8206132 DOM parser does not honor DocumentBuilderFactory.setExpandEntityReferences(false)
  3. JDK-8217937

Release Note: Change DOM Parser to Not Resolve EntityReference and Add Text Node with DocumentBuilderFactory.setExpandEntityReferences(false)

    Details

    • Type: Sub-task
    • Status: Closed
    • Priority: P4
    • Resolution: Delivered
    • Affects Version/s: 13
    • Fix Version/s: 13
    • Component/s: xml

      Description

      The implementation of the `ExpandEntityReferences` feature was changed to comply with the specification of the `DocumentBuilderFactory.setExpandEntityReferences` method. Specifically, now when the method is set to `false` and encounters an entity reference, a DOM parser created by the `DocumentBuilderFactory` adds the `EntityReference` node to the DOM tree without the expanded Text node. Before the change, the implementation incorrectly added both nodes.

      With the change, the DOM parser no longer reads and resolves entity references when the feature `ExpandEntityReferences` is set to false. For applications that intend to avoid resolving entity references, it will work as expected.

      This change also affects the DOM Load and Save parser. The `entities` parameter is aligned with the `ExpandEntityReferences` feature, so that setting the `entities` parameter to `true` is equivalent to setting `ExpandEntityReferences` to `false`. In the following code snippet, the `document` will contain `EntityReference` nodes but not expanded `Text` nodes:
      ```
              LSParser domParser = domImplementationLS.createLSParser(MODE_SYNCHRONOUS, null);
              domParser.getDomConfig().setParameter("entities", true);
              LSInput src = domImplementationLS.createLSInput();
              src.setStringData(source);
              Document document = domParser.parse(src);
      ```
      Because the references are not resolved, the resulting string will contain entity references without the text when the `document` is serialized:
      ```
              LSSerializer lsSerializer = domImplementationLS.createLSSerializer();
              lsSerializer.getDomConfig().setParameter("format-pretty-print", true);
              String result = lsSerializer.writeToString(document);
      ```

        Attachments

          Activity

            People

            • Assignee:
              joehw Joe Wang
              Reporter:
              joehw Joe Wang
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: