Chapter 4. Mapping Data

In this chapter, we will cover the following recipes to transform data from one format to another:

  • Ignoring missing elements with XSLT
  • Ignoring missing elements with Assign
  • Creating target elements in Assign
  • Array processing with XSLT
  • Array processing with BPEL Assign
  • Overriding mapping of EJB data to XML
  • Ignoring a Java property
  • Creating a wrapper element for a Java collection or array
  • Handling an abstract class

Introduction

At the heart of any solution built with SOA Suite is the transformation of data from one format to another. Within SOA Suite we have two explicit mechanisms to deal with this, namely XML Stylesheet Transforms (XSLT) or XPath Assigns. Transformation may also occur implicitly as a result of using a component or adapter, for example converting to/from Java formats when using Java components and adapters.

Comparison of XSLT and Assign

Within both the Mediator and BPEL components, we have the choice between using XSLT transformation and XPath Assigns. When we use an XPath Assign, we are manipulating the target XML document directly. This may be more efficient when we are adding or altering a small part of the target document and the target document already contains data. When we use an XSLT transform, we are replacing the target XML document with a new one generated from the transform.

Tip

Choosing between Assign and Transform

Generally when we are populating a new variable for the first time, it is best to use a transform. A transform is also easier to use when manipulating repeating elements in the target. When we wish to modify only a few elements in the target, Assign is the easiest way to do this.

A common pattern is to perform an initial mapping to a variable by using XSLT and then making subsequent additions or modifications using Assign. The reverse pattern cannot be used because an XSLT transform will completely replace a variable with new content, losing any previous assignments to that variable.

Typing in XML Schema

Although XML Schema allows for element contents to be typed, generally the data transformation process is quite lax about enforcing type constraints, and as long as the data being transformed is compatible in its string form with the target type, no errors will be thrown; for example, the string 75 may be assigned to a numeric type without error, and similarly a numeric type such as 12.5 may be safely assigned to a string.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.167.183