How to decode HTML objects

I have a string variable with HTML objects:

var str = 'Some text & text';

I want to convert (decode) it to the original characters:

Some text & text .

JavaScript does not have a built-in function to achieve the desired result. I cannot use jQuery or DOM objects because I need it to work in Google Apps Script.

How can I do this in a simple way?

+4
source share
1 answer

You can use the built-in Xml services:

 var str = 'Some text &#x26; text'; var decode = XmlService.parse('<d>' + str + '</d>'); var strDecoded = decode.getElement().getText(); 

or you can use the built-in XML class E4X.

 var str = 'Some text &#x26; text'; var decode = new XML('<d>' + str + '</d>'); var strDecoded = decode.toString(); 
+12
source

All Articles