Altova MapForce 2025 Enterprise Edition

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.

mf-func-charset-decode

 

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 ic_utf8_replacement_char.

 

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"?>
<message xsi:noNamespaceSchemaLocation="message.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">TG9yZW0gaXBzdW0=</message>

 

The data type of the message element is xs:base64Binary, as illustrated by the schema:

 

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="message" type="xs:base64Binary"/>
</xs:schema>

 

A mapping that decodes the message above looks as follows:

mf_charset-decode_02

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:

mf_charset-decode_03

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.

© 2018-2024 Altova GmbH