I am using XML DOM techniques to build a pulldown menu in JavaScript.
After I create an <option>
node, I append the text that is supposed to appear for that option. The problem I am facing is that when the text contains character entity references (CERs) such as ₂
the & character of the CER is being escaped to &
, so that the CER and not the character is displayed in the select menu when the menu is outputted to the page for display.
I have tried both of the following methods: optionNode.appendChild(xmlDoc.createTextNode(label)); and
optionNode.textContent = label;
And both give the same result. I can work around the problem by doing a global replace of &
with &
after I output the XML document to text:
var xml = (new XMLSerializer()).serializeToString(xmlDoc);
return xml.replace(/&/g, '&');
But I'm sure there must be a way to avoid the escaping in the first place. Is there?