Skip to content

qie.base64DecodeXML

Signature: qie.base64DecodeXML(input, contentType*)

Returns: String decodedValue - the decoded value

Decode the Base64 encoded input value.

Note

contentType is optional. When not specified, the encoding is read from the prolog in the input, falling back to UTF-8. When specified, it is consulted only if the input has no prolog.

Parameters

Type Name Description Default
String input the Base64 encoded XML value
String contentType* (optional) the content type for the inbound XML value

Example

var xmlMessage = '' +
   '<?xml version="1.0" encoding="GB2312"?>' +
   '<message>' +
   '    <prologue>奇怪的中文编码: 这是一段包含奇怪编码的 XML 内容!</prologue>' +
   '    <greeting>Hello, world!</greeting>' +
   '    <sentiment>Love and kindness are what make life beautiful. ❤️</sentiment>' +
   '    <emoji>😊</emoji>' +
   '    <footer>Stay happy and spread joy!</footer>' +
   '</message>';
var base64EncodedXml = qie.base64Encode(xmlMessage, 'GB2312');
var incorrectDecodedXmlValue = qie.base64Decode(base64EncodedXml);
/* The incorrectDecodedXmlValue was incorrectly decoded because UTF-8 was assumed because we used
   the base64Decode method when we needed to have used the base64DecodeXML method which
   reads the xml prolog to determine the correct encoding. */
var correctlyDecodedXmlValue = qie.base64DecodeXML(base64EncodedXml);
/* This correctlyDecodedXmlValue value was correctly decoded because it was based on the XML
   prolog that had the proper encoding */