3.3. Integrating HTTP content

The XDIME following page presents weather conditions for Seattle, WA, the Jive Headquarters. The information is provided by the Yahoo! Weather service. The XSL transformation is used to filter and convert the data to XDIME.

The XDIME following page presents weather conditions for Seattle, WA, the Jive Headquarters. The information is provided by the Yahoo! Weather service. The XSL transformation is used to filter and convert the data to XDIME.

Our Offices

Request parameters, headers and cookies

  1. The page must contain the namespace declarations for the pipeline and web driver elements
    xmlns:pipeline="http://www.volantis.com/xmlns/marlin-pipeline"
    xmlns:webd="http://www.volantis.com/xmlns/marlin-web-driver"
  2. The webd:get element represents the HTTP GET method. Its url attribute specifies URL of the web service, including protocol and ports. In our case, it's Yahoo! Weather.
    <webd:get url="http://weather.yahooapis.com/forecastrss">
      <webd:parameters>
        <webd:parameter name="p" value="USWA0395"/>
        <webd:parameter name="u" value="c"/>
      </webd:parameters>
    </webd:get>
  3. webd:parameter defines an HTTP parameter. The name attribute specifies the name of a parameter, and value defines its value. The webd:parameters element may contain multiple parameter elements. All specified parameters will be appended to the end of the URL. The p parameter specifies the location. The ID 'USWA0395' corresponds to Seattle, WA. The u parameter defines the temperature units. The possible values are: 'c' and 'f'.

Using transforms

  1. You use the pipeline:transform element to define an XSL transforms on pipeline content
    <pipeline:transform href="xsl/http2xdime.xsl">
      <webd:get url="http://weather.yahooapis.com/forecastrss">
        <webd:parameters>
          <webd:parameter name="p" value="USWA0395"/>
          <webd:parameter name="u" value="c"/>
        </webd:parameters>
      </webd:get>
    </pipeline:transform>
  2. The http2xdime.xsl transform, created in the previous module, converts the data to XDIME in runtime. This XDIME fragment is then added to the final page.

Handling pipeline errors

You may provide for alternative content in case a remote service fails for any reason.

  1. You use the pipeline:try element to define preferred content and a series of alternatives
    <pipeline:try>
      <pipeline:preferred>
        <pipeline:transform href="xsl/http2xdime.xsl">
          <webd:get url="http://weather.yahooapis.com/forecastrss">
            <webd:parameters>
              <webd:parameter name="p" value="USWA0395"/>
              <webd:parameter name="u" value="c"/>
            </webd:parameters>
          </webd:get>
        </pipeline:transform>
      </pipeline:preferred>
      <pipeline:alternative>
        <pipeline:content>
          <p>There was a problem retrieving the information requested.</p>
        </pipeline:content>
      </pipeline:alternative>
    </pipeline:try>
  2. The pipeline:preferred element is the first container processed. If it is not available, MCS moves on to any pipeline:alternative elements in the order you list them.

  3. The pipeline:content element specifies mixed content. The element is parsed as an XML document fragment, which means that it can contain multiple root elements and text.

Complete XDIME 2 code

  1. Create a dci_ourOffices.xdime file in the ${MCS_HOME}/webapps/mcs.war/tutorial/ directory

  2. Modify the dci_ourOffices.xdime file by including the following code
    <?xml version="1.0" encoding="UTF-8"?>
    <html xmlns="http://www.w3.org/2002/06/xhtml2"
      xmlns:mcs="http://www.volantis.com/xmlns/2006/01/xdime/mcs"
      xmlns:urid="http://www.volantis.com/xmlns/marlin-uri-driver"
      xmlns:pipeline="http://www.volantis.com/xmlns/marlin-pipeline"
      xmlns:webd="http://www.volantis.com/xmlns/marlin-web-driver">
      <head>
        <title>Weather Forecast for Our Headquarters</title>
        <!--Links to the layout and theme for this page -->
        <link rel="mcs:layout" href="/jivearticle.mlyt"/>
        <link rel="mcs:theme" href="/jive.mthm"/>
      </head>
      <!-- Page body -->
      <body>
        <!-- The common material for the page header -->
        <urid:fetch href="jiveheader.xdinc"/>
        <!-- Page Title -->
        <h2 id="title">Weather Forecast for Our Headquarters</h2>
        <!-- The article -->
        <div id="article">
          <pipeline:try>
            <pipeline:preferred>
              <pipeline:transform href="xsl/http2xdime.xsl">
                <webd:get url="http://weather.yahooapis.com/forecastrss">
                  <webd:parameters>
                    <webd:parameter name="p" value="USWA0395"/>
                    <webd:parameter name="u" value="c"/>
                  </webd:parameters>
                </webd:get>
              </pipeline:transform>
            </pipeline:preferred>
            <pipeline:alternative>
              <pipeline:content>
                <p>There was a problem retrieving the information requested.</p>
              </pipeline:content>
            </pipeline:alternative>
          </pipeline:try>
        </div>
        <!-- The common material for the page footer -->
        <urid:fetch href="jivefooter.xdinc"/>
      </body>
    </html>

Checklist

Name Purpose
a

Used to create an explicit link to another place in the same document or to another document. The current document is the source of the link and the value of the href attribute, defines the link target

body

Contains the document's content.

div

A section used to add extra structure to documents. Style sheets can be used to control the presentation.

h1, h2, h3, h4, h5, h6

Heading elements for sections within a document. The number associated with each element indicates its relative position in the hierarchy of headings, with 1 indicating the beginning level and 6 the ending level.

head

Information such as the title and other metadata that is not document content. The contained title element is required and it must be the first child of the head element.

html

The container for the XDIME 2 document.

link

Defines a link. Multiple links and relationships may be defined for a single document. Refer to the topic entitled Document relationship links for more information.

pipeline:alternative

Contains alternative content inside a try element.

pipeline:content

Allows you to specify mixed content. Pipeline markup within the element will cause a streaming error.

pipeline:preferred

Contains preferred content inside a try element. It must contain one or more pipeline operation elements.

pipeline:transform

The root element for a transform.

pipeline:try

Provides both preferred and alternative content if there are errors in the pipeline.

title

The title element is used to identify the document. title is required and it must be the first child of the head element.

urid:fetch

Specifies a driver URI.

webd:get

Represents the HTTP GET method.

webd:parameter

Defines an HTTP parameter. There are also element forms for some attribute values.

webd:parameters

Container for multiple parameter elements.

webd:post

Represents the HTTP POST method.

Core attributes

Attributes that are common to XDIME 2 elements.