Thank you both for your replies. I tried out
String.fromCharCode as it looked promising
however it actually generates the actual character instead of inserting the literal HTML entity itself. So when I serialized the DOM fragment it displayed two spaces at the end of each sentence instead of outputting the entity.
So then I decided if it's going to RENDER the entity I could maybe fool the computer in to rendering the ampersand
before the entity (minus the leading ampersand).
var mystring = mystring.replace(/\. /g,'. '+String.fromCharCode(38)+' #160; ');
The result?
 
...nope.
Yes Aname, I am using the createTextNode method. My approach is to use string replacement to clean up the strings before generating the text node though. Penders mentioned that using the createTextNode method would output the
literal string version of the entity so I did a quick test...
var test = document.createTextNode(' ');
alert(test.nodeValue);
...it outputs....
 
...as desired!
So I'm left with a few choices at this time. I can continue seeing if I can output a literal string version of an HTML entity (perhaps though I think unlikely unless it's buried deep in DOM 1/2/3 documentation) or I could split the text string and create a node (with a dedicated node for the entity) in a fashion and merge them together in to a single string. I also just tried the following...
var a1 = '&';
var a2 = '#160;';
var a3 = a1+a2;
alert(a1+a2+'\n\n'+a3);
...which does output the literal string version of he HTML entity. So I tried the following...
var en1 = '&';
var en2 = '#160;';
var mystring = mystring.replace(/\. /g,'. '+en1+en2+' ');
...which doesn't work go figure.
So unless someone comes across a method that doesn't seem to exist I think since regular expressions won't output literal string versions of HTML entities I'm going to have to split the main string where I want to regex the entity in to the string, insert the string at the end of each text node and then finally loop through the generated textNodes and append them to the end...
Okay here we go... The problem was that while working with the string that is a
nodeValue browsers will attempt to escape ampersands. So I did the following...
var mystring = String(node.nodeValue);
mystring = mystring.replace(/\. /g,'.   ');
...which works!
The odd thing to keep in mind is that when alerting the
typeof of a nodeValue string is that the browser will still tell you that it's a
string while still treating it as direct (X)HTML.
So I have my answer, thank you both! This really helps me clean up the output of the editor I'm working on. :)
- John