How to disable/avoid Ampersand-Escaping in Java-XML? How to disable/avoid Ampersand-Escaping in Java-XML? xml xml

How to disable/avoid Ampersand-Escaping in Java-XML?


Use output escaping as follows:

Node disableEscaping = document.createProcessingInstruction(StreamResult.PI_DISABLE_OUTPUT_ESCAPING, "&"); Element element = document.createElement("element"); element.setTextContent(" "); document.appendChild(disableEscaping ); document.appendChild(element);Node enableEscaping = document.createProcessingInstruction(StreamResult.PI_ENABLE_OUTPUT_ESCAPING, "&");document.appendChild(enableEscaping )


Set the text content directly to the character you want, and the serializer will escape it for you if necessary:

element.setTextContent("\u00A0");


Try to use

element.appendChild (document.createCDATASection (" "));

instead of

element.setTextContent(...);

You'll get this in your xml: It may work if I understand correctly what you're trying to do.