When you try to call setTextContent () with a string containing <or>, the final file is written to & lt or & rt. What to do and how to write these marks in the content of the element?
1 answer
As I wrote in the commentary, in accordance with the standard, the < character should only appear at the beginning of the tag, and the > character at the end, in all other cases, they must be converted to escape sequences < and > . The appearance of these characters in unshielded form in place of text nodes will make the document invalid and will most likely break its display in browsers. The only exception is text nodes wrapped in a CDATA section:
someNode.appendChild(doc.createCDATASection("<>")); But, as far as I understand, this option does not suit you either. Perhaps you are interested in something like this:
Node disableEscaping = doc.createProcessingInstruction(StreamResult.PI_DISABLE_OUTPUT_ESCAPING, "<>"); Node enableEscaping = doc.createProcessingInstruction(StreamResult.PI_ENABLE_OUTPUT_ESCAPING, "<>"); someNode.appendChild(disableEscaping); someNode.setTextContent("> <"); someNode.appendChild(enableEscaping); - I just need CDATA! I am writing a feed generator for Ya. Dzen, and there the main content is wrapped in this tag ... - Artyom Akzhigitov
- Then I'm glad I mentioned it. - Sergey Gornostaev
|