charset-decode
The charset-decode function takes as input binary data encoded as Base64 text. It decodes data according to the specified character set (for example, "utf-8") and returns the resulting string value. If you need to encode binary data as Base64 text, use the charset-encode function.
Languages
Built-in.
Parameters
Name | Type | Description |
---|---|---|
binary-data | xs:base64Binary | The binary data as Base64 text. |
encoding | xs:string | The character set used for encoding (for example, "utf-8"). |
error-abort | xs:boolean | Optional argument that specifies how processing should continue when errors are encountered. Valid values:
•true - End processing with an exception on the invalid character. •false - Continue processing, and replace invalid characters with the replacement character .
The default value is true. |
Example
Let's suppose that you would like to decode binary data originating from the following source XML file. Notice that the message element contains binary data encoded as Base64 text.
<?xml version="1.0" encoding="UTF-8"?> |
The data type of the message element is xs:base64Binary, as illustrated by the schema:
<?xml version="1.0" encoding="UTF-8"?> |
A mapping that decodes the message above looks as follows:
The mapping in this example outputs the text "Lorem ipsum".
A mapping can also process text or XML files encoded as Base64 data, with the help of a MapForce serialization component. For example, the mapping illustrated below has an input parameter which expects Base64 text data. Assuming that the Base64 data was created from an XML file as shown in the charset-encode example, you can recreate the original XML file as shown in the mapping below:
In this mapping, the error-abort argument gets a false value, which was produced with the help of the boolean built-in function. This ensures that processing will continue even if invalid characters are encountered. The string result of the function is then passed to an XML parsing component which converts it to an XML file. Note that, in order for XML parsing to be possible, you must have the XSD schema file. For more information, see Parsing and Serializing Strings.