This section continues implementing the requirements of New Horizons Requirements. The aim is to read an XML document with a booking and insert it in database tables “booking” and “visit”. In section Sending to Database , we did the insert in table “booking”. The inserted values were fetched using XPath expressions. In the previous section Transformation with XSLT, we transformed the booking XML such that the values for each “visit” row are grouped together. In this section, we will insert these rows.

A booking can have multiple destinations, each appearing in their own <destination> element. These elements can be iterated with the <ForEachChildElementPipe>. Within this pipe you include a sender that is applied to each element, in our case a <destination> element. Please do the following to do the inserts in table “visit”:

  1. Please open Configuration.xml.

  2. Add a <ForEachChildElementPipe> as shown:

            <Forward name="success" path="iterateDestinations"/>
              <!-- You will add your sender here -->
            <Forward name="success" path="Exit"/>

The <ForEachChildElementPipe> applies the elementXPathExpression to the incoming message and iterates over the result set. In the transformed example booking shown in Transformation with XSLT, there is one match:

  1. Replace the <!-- You will add your sender here --> line with the following XML:

        query="INSERT INTO visit VALUES(?, ?, ?, ?, ?, ?, ?)"
      <Param name="bookingId" xpathExpression="/destination/bookingId" />
      <Param name="seq" xpathExpression="/destination/seq" />
      <Param name="hostId" xpathExpression="/destination/hostId" />
      <Param name="productId" xpathExpression="/destination/productId" />
      <Param name="startDate" xpathExpression="/destination/startDate" />
      <Param name="endDate" xpathExpression="/destination/endDate" />
      <Param name="price" xpathExpression="/destination/price" />

This sender is similar to the sender of section Sending to Database. There is an INSERT query with a question mark for each inserted value. The inserted values are fetched using XPath expressions, which act on the current match of the elementXPathExpression as shown at step 2.