charset-encode
The charset-encode function takes as input string data and encodes it as Base64 text. Data is encoded in the specified character set (for example, "utf-8") and returned as xs:base64Binary type. If you need to decode binary data previously encoded as Base64 text, use the charset-decode function.

Languages
Built-in.
Parameters
Name | Type | Description |
---|---|---|
string-data | xs:string | The string data to be encoded. |
encoding | xs:string | The character set used for encoding (for example, "utf-8"). |
substitute | xs:string | Optional argument that specifies a replacement character when invalid characters are encountered. This argument is applicable if you use a non-Unicode encoding. For Unicode encodings, the replacement character is |
Example
Let's suppose that you would like to encode the text "Lorem ipsum" as Base64 data, using the UTF-8 character set, and write it to a target XML file. The target XML file has a message element of xs:base64Binary type, as illustrated by the schema:
<?xml version="1.0" encoding="UTF-8"?> |
A mapping that performs the Base64 encoding looks as follows:

This mapping produces XML output like the one below (the schema references and XML declaration were skipped):
<message>TG9yZW0gaXBzdW0=</message> |
You can also encode text or XML files as Base64, with the help of a MapForce serialization component. For example, the mapping illustrated below serializes a source XML file to a string. The resulting string is then supplied as argument to the charset-encode function. Finally, the function result is returned as mapping output, with the help of a simple output component, see Returning String Values from a Mapping. For more information about serialization, see Parsing and Serializing Strings.
