Calling [Element].appendtext(" ")
causes the ampersand to be escaped and so the user sees the ampersand on the rendered HTML page. I don't want the page to render the HTML code.
I actually do want the html page to render whitespace.
A non-breaking space can be written into a string literal using a Unicode escape sequence: "\u00A0"
.
However, if you want all whitespace within an element to be rendered literally, consider using normal spaces but applying a CSS property such as white-space: pre;
.