qie.base64DecodeXML¶
Signature: qie.base64DecodeXML(input, contentType*)
Returns: String decodedValue - the decoded value
Decode the Base64 encoded input value.
Note
This function checks for a prolog in the input and use the encoding defined in the prolog. If no prolog is found, then it will look for an encoding found in contentType. If no encoding is found, then it will default to 'UTF-8'.
Parameters¶
| Type | Name | Description | Default |
|---|---|---|---|
| String | input | the Base64 encoded XML value | |
| String | contentType* | (optional) the content type for the inbound XML value | UTF-8 |
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 */