Copying Substrings of XML Data

Use the substring operation to copy part of a string from a received XML document and assign it to a variable or an element in Eclipse, or to an XML element for a sent document. For example, you can copy the first four digits of a credit card number to identify the bank associated with the card. Using the substring operation, you can specify how many characters and the starting character position to copy. For example, if you know that a string always contains 16 characters, and to extract the fourth, fifth, and sixth characters, use the substring operation to indicate the fourth character as the starting character and that you want to copy three characters.

If you receive data in a string that is not always a consistent length, use the extract field operation to indicate the delimiter and the field within the string to copy.

To copy a substring of XML data:

  1. Access the Business Connect XML mapping utility.

  2. Right-click a transaction in the Trading Partner Tree and select Edit Transaction Map to display the transaction map.

  3. In the Target XML column of either the received map or the reply/sent map, right-click the element to modify and select Modify Mapping to display the XML Mapping Conversion Editor dialog box.

If the element you select has a source element mapped to it, the source element displays in the Operation Stack field. If the element is not mapped, the Operation Stack field is blank.

  1. From the Operations field, double-click Substring to add it to the Operation Stack field.

The Sub-String Parameters dialog box displays.

  1. In the Start Index field, enter the first character position of the string you want to copy.

  2. In the Number of Characters field, enter the number of characters to copy.

For example, if you want to copy data from characters in the fourth, fifth, and sixth positions, enter 4 in the Star Index field and 3 in the Number Of Bytes field.

  1. Click OK to return to the XML Mapping Conversion Editor dialog box.

  2. If necessary, move the operation to the correct location in the operation stack.

The substring operation line falls after the data that contains the substring from which you want to copy data:

  1. Add additional sources and operations, as necessary.

  2. Click OK to return to the mapping utility main window.

  3. From the File menu, select Save Transaction Map to save the map.

See Also:

Modifying Incoming and Outgoing XML Data Overview

Extracting Fields from Delimited XML Strings