Using an XPATH Expression to Query an XML Document

In this section:

There are two methods for determining if a function error has occurred in iWay Transformer. Both methods use a Decision Switch object in the iWay Designer process flow. The Decision Switch object contains an XPATH expression that queries an XML document, seeking a match on the following string:

TRANSFORM_FUNCTION_ERROR

The following image shows a sample XML output document with the TRANSFORM_FUNCTION_ERROR string at the location of two failed function nodes.

After you detect a function error, you can create a failed state through the use of services such as XDFailAgent. The service XDFailAgent generates an artificial exception.

Tip: Depending on your application requirements, you can use both methods to formulate a hybrid approach or a sequential approach to determine if function errors have occurred.


Top of page

x
Searching a Specific Node in an XML Document

In the first method, the iWay Designer Decision Switch object contains an XPATH expression that searches a specific node (location) in an XML document.

This method:

The Decision Switch object code for this method is:

XPATH(/Root/Node_1/Node_2/.../Node_n/Function) Equal To TRANSFORM_FUNCTION_ERROR


Example: Searching a Specific Node in an XML Document

In this sample iWay transform, the XML input document contains information on car sales, including the name of the customer, the cost of the car sold, and the country in which the car was manufactured. The iWay transform retains the information from the XML input document (customer name, car cost, and country of origin), and enriches the document on output with four iWay-supplied, pre-defined functions.

Using the @DATE(date_format) function, the iWay transform adds the current date to the XML output document. Using the @CONCAT(string,string,string) function, the transform adds an element that indicates which country of origin the customer prefers.

The iWay transform also adds the @TRIM(string) function and @CUSTOMDATE(picture_mask) functions to supply company-required information in the XML output document. However, those two functions were added incorrectly. Instead of supplying the required information, the XML output document contains the string TRANSFORM_FUNCTION_ERROR in the two failed function nodes.

The following image shows the XML output document that is generated when the process flow that contains the iWay transform is run. The two failed function nodes (with element names TRIM and CUSTOM_DATE) are the last two in the document.

At design time, you can detect function errors and correct them.

  1. In iWay Designer, open the process flow that contains the iWay transform.
  2. Add an iWay Designer Decision Switch object, assign a name to it, and optionally supply a description.

    In the following image, the process flow that contains the iWay transform is open in iWay Designer. The cursor is pointing to the Decision Switch object on the toolbar.

  3. In the Switch Expression dialog box, click the down arrow in the input field, and click Add/Edit.
  4. In the Add / Edit dialog box, type the XPATH expression that queries the XML output document.

    In this example, the XPATH expression searches a specific node (with element name TRIM) for the string TRANSFORM_FUNCTION_ERROR:

    XPATH(/INFO/WHO/HOW_MUCH/WHERE/WHEN/DESCRIPTION/TRIM) Equal To
     TRANSFORM_FUNCTION_ERROR

  5. In the Switch Cases dialog box....

Top of page

x
Searching All Nodes in an XML Document

In the second method, the iWay Designer Decision Switch object contains an XPATH expression with a wild card that searches all nodes (locations) in an XML document.

This method:

The Decision Switch object code for this method is:

XPATH(//*[value() = 'TRANSFORM_FUNCTION_ERROR']) IsNotNull

iWay Software