-
Sub-task
-
Resolution: Delivered
-
P4
-
13
-
Verified
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);
```
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);
```