'Entity reference is not shown in the XML

I create entity reference with EntityReference ent = doc.createEntityReference(txt). Then I add it to the node: node.appendChild(ent); and the txt is like "lt". So, I expect to see < in my XML file. But all entity references are missing. Other elements are added and shown well, but not EntityReference.

XML is created as:

        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        docBuilder = docFactory.newDocumentBuilder();
        doc = docBuilder.newDocument();

dumping to the file:

        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        Transformer transformer = transformerFactory.newTransformer();
        DOMSource source = new DOMSource(doc);
        StreamResult result = new StreamResult(new StringWriter());
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.transform(source, result);
        String xmlString = result.getWriter().toString();
        return xmlString;

The result XML has a standard header:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
...

Where can be a problem?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source