Putting XML in a form or page

About this task

A form is a perfect vehicle for XML. You can enter the XML tags, and include fields within the tags for data. The result is an XML document with data that is meaningful when delivered to an XML parser.

You can also put XML on a page. A page in IBM® Domino® Designer is a database design element that displays information. You can use a page for traditional application content, such as a home page, or you can use XML tags to describe the data on a page. As you will see in the section on using XML in a view, a page is useful for embedding a view and adding the required XML tags to process the view. A page is also useful for creating an extensible stylesheet (XSL) or a cascading style sheet (CSS) to direct a server or browser on how to format data described with XML tags.

Defining data on a form with XML elements

About this task

When you use XML elements on a form or page, you must follow the rules for constructing valid XML and you must properly format the XML tags.

XML tags look very much like HTML tags. There are some different rules for structuring the XML tags that you must adhere to when marking up data. For example, requirements for nesting XML are more rigid than those for nesting HTML tags. For information on marking data with XML tags, visit the IBM® XML Web site at http://www.ibm.com/xml.

As an example of using XML on a form, the entries for each book in an online book catalog might look like this:

<?xml version="1.0" encoding="UTF-8"?>
<BOOK>
	<bookTitle>Chess for the Master</bookTitle>
	<bookCategory>Games</bookCategory>
	<bookAuthor>Alice B. Charles</bookAuthor>
	<bookPrice>10</bookPrice>
	<bookListPrice>12</bookListPrice>
	<bookISBN>0-980-38475-81</bookISBN>
	<bookDatePublished>April 1997</bookDatePublished>
	<bookAbstract>The authority on all the latest chess moves, including the entire Big Blue arsenal.</bookAbstract>
</BOOK>
Note: XML tags are case-sensitive. The tags <book>, <Book> and <BOOK> are all different. Opening and closing tags must match case exactly for the XML to be well-formed.

To create documents in XML format

Procedure

  1. Create a new form or page.
  2. Enter the document type declaration -- that is:
    <?xml version="1.0" ?> 

    You can optionally add an encoding reference -- such as:

    <?xml version="1.0" encoding="UTF-8" ?>
  3. Enter the XML elements, generally a root element with sub elements.
  4. Enter the fields that will hold the data you are marking with XML.
  5. Choose Design - Form Properties.
  6. On the Form Info tab, choose "Render pass through HTML in Notes®."

    This property tells Domino® to pass all of the document text to the HTTP requester without generating HTML tags.

  7. Save and close the form.
  8. To view the documents created from the form, create a view that uses a form formula that resolves to the name of the XML form.

Formatting XML data with stylesheets

About this task

One of the attributes of XML is that it only describes data, and says nothing about the presentation of the data. The presentation is not important on computer-to-computer transactions -- it only matters if you are presenting the data to a user -- for example by posting it on a Web site. XML documents typically rely on a stylesheet to determine the layout and presentation of the data. Some browsers provide simple default styles for popular elements such as <Para>, <List>, and <Item>, but generally you must use a stylesheet to describe the data format. There are two types of stylesheets you can use with XML:

  • An extensible stylesheet language (XSL) describes how to transform XML into HTML or into another version of XML.
  • A cascading stylesheet (CSS) styles XML directly on Web browsers that support CSS.

To use a stylesheet, insert the stylesheet reference tag immediately after the document type declaration and before the root element. For example:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="bookdisplay.css"?>
<BOOK>

If you create a stylesheet on a page, set the page property to "Treat page contents as HTML."

An XSL stylesheet that transforms information on books to HTML might look something like this:

<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl" > 
<xsl:template pattern="BOOK">
	<HTML>
	<HEAD>
	<TITLE><xsl:value-of select="BOOKTITLE" /></TITLE>
	</HEAD>
	<BODY bgcolor="F0FFF8">
	<B><xsl:value-of select="BOOKAUTHOR"/></B>
	</BODY>
	</HTML>
</xsl:template>
</xsl:stylesheet>
<?xml:stylesheet type="text/xsl" href="/roibooks.nsf/bookform.xsl"?>

A cascading stylesheet (CSS), instead of transforming XML into HTML, provides instructions directly to the server regarding how to format each XML element. A CSS for books might look like this:

BOOK {
  display: block;
  border: 1px solid #cccccc;
}
BOOKTITLE {
 display: block;
 float: left;
 margin-right: 10px;
 padding: 5px;
}
BOOKAUTHOR {
  display: block;
  font-style: italic;
}