How to Customize Web Pages

You must first evaluate the format of the web service invoked by the HTTP web server to customize your web pages. For example, web pages are formatted in HTML when the web service specifies the HTML type.

The RAW web service type provides the most customization because it requires that web service procedures and functions explicitly require coding to provide the required markup such as HTML or XML. The following tasks must be performed to customize web pages when using the RAW type:

Example

The following example illustrates how to create a new web service with the RAW type specified:

CREATE SERVICE WebServiceName 
    TYPE 'RAW'
    AUTHORIZATION OFF 
    URL ON
    USER DBA
    AS CALL HomePage( :url );

In this example, the web service calls the HomePage stored procedure, which is required to define a single URL parameter that receives the PATH component of the URL.

Setting the Content-Type header field

Use the sa_set_http_header system procedure to define the HTTP Content-Type header to ensure that web browsers correctly render the content.

The following example illustrates how to format web page output in HTML using the text/html MIME-type with the sa_set_http_header system procedure:

CREATE PROCEDURE HomePage (IN url LONG VARCHAR)
    RESULT (html_doc XML)
    BEGIN
        CALL sa_set_http_header ( 'Content-Type', 'text/html' );
        -- Your SQL code goes here.
        ...
    END

Applying tagging conventions of the MIME-type

You must apply the tagging conventions of the MIME-type specified by the Content-Type header in your stored procedure. SAP Sybase IQ provides several functions that allow you to create tags.

The following example illustrates how to use the XMLCONCAT, and XMLELEMENT functions to generate HTML content, assuming that the sa_set_http_header system procedure is used to set the Content-Type header to the text/html MIME-type:

XMLCONCAT(
   CAST('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">' AS XML),
   XMLELEMENT(
        'HTML',
        XMLELEMENT(
            'HEAD',
            XMLELEMENT('TITLE', 'My Home Page')
        ),
        XMLELEMENT(
            'BODY',
            XMLELEMENT('H1', 'My home on the web'),
            XMLELEMENT('P', 'Thank you for visiting my web site!')
        )
    )
)

Since element content is always escaped unless the data type is XML, the above example uses the CAST function. Otherwise, special characters are escaped (for example, &lt; for <).