Liquid XML Studio
CharToCode
See Also Send Feedback
Data Mapping > Data Mapper Functions > By Category > String > CharToCode

Glossary Item Box

Function Name
CharToCode
Category
String
Icon
CharToCode
Description
Convert character data to Unicode
Inputs
String String containing character
Outputs
Result Input character represented in Unicode
Properties
None -

Usage

The Data Mapper String CharToCode function returns the Unicode representation of a single character input String, or the first character in a longer String. Often, XML data is mapped for use between differing Web and desktop applications, so the ability to convert data to different formats is essential. Converting character data to Unicode is therefore a useful facility. To apply the String ChartoCode transform function, use the following process:

Create a new Data Mapper file, dragging your XML data source and targets into the editor area. For this example we are using document_source.xsd, an XML Schema Definition inferred from the following source:

Source XML Copy Code
<docs>
 <document>
  <title>My Data File</title>
  <content>Here is my content</content>
  <type>b</type>
 </document>
 <document>
  <title>Another File</title>
  <content>Here is some more content</content>
  <type>r</type>
 </document>
</docs>

For our target schema we will be using document_target.xsd, inferred from the following XML:

Target XML Copy Code
<data_files>
 <file type="99" name="My File">Here is my content</file>
 <file type="115" name="His File">Here is his content</file>
</data_files>

The data models documents, with the "type" item using a single character. Here is the Data Mapper with Source and Target imported:

Data Mapper Source and Target

Drag the String CharToCode function from the Component Palette into the mapping area:

String CharToCode Component

String CharToCode Transform Added

The String CharToCode function takes a single input and gives a single output. The input should be connected to the source text String item to retrieve the Unicode representation of. The output should be connected to the target item, whether an item in the XML Writer or another component in the Mapper. In this case we are mapping from an element in the source to an attribute in the target, converting to Unicode at the same time. Connect the XML Reader "type" output to the CharToCode input:

XML Reader to CharToCode

Now connect the CharToCode output to the "type" item in the XML Writer:

CharToCode to XML Writer

Finally, connect the remaining inputs and outputs:

Input and Output Connections Mapped

We can now execute the transform by pressing Shift-F5 or the Execute button (Execute). The transform is applied and the file we selected as output opens in the editor:

Output XML Copy Code
<data_files>
 <file type="98" name="My Data File">Here is my content</file>
 <file type="114" name="Another File">Here is some more content</file>
</data_files>

The "type" items have been converted from character to Unicode data as part of the mapping process. The result is that the characters are now represented numerically.

If the CharToCode function receives an input String with more than one character in it, it will output the code for the first character.

This is a scalar function so the standard rules apply if multiple values are presented to one or more inputs.

See Also