LDD Today


Exercising XML in Domino Designer
by
Kyla
Town

Level: Intermediate
Works with: Designer 5.0
Updated: 02-Jan-2001


The development of applications using XML (Extensible Markup Language) is rapidly picking up steam. XML provides the power to create markup languages that describe data. You can use it to share data across a network, and even across applications.

Where does Domino Designer fit into this new technology? In addition to workflow and security capabilities, Domino Designer provides a medium for writing XML and then serving the XML data to a parser. Domino Designer is a powerful development environment that provides the layers of security needed to protect data, including database access control and field encryption.

To illustrate how to integrate XML into a Domino application, this article will walk you through the process of creating elements of an online auto parts catalog for a fictional store called Acme Auto Parts. You will learn how to:
You can also download two sample databases, Acme.nsf and Zippy.nsf, from the Iris Sandbox on Notes.net. These databases contain all the design elements and code discussed in this article.

Please note the following requirements:
For general information about creating databases, outlines, agents, and framesets, see Domino 5 Designer Help. For general information about XML and XSL (Extensible Stylesheet Language), see the World Wide Web Consortium (W3C).

The scenario
In this example, Acme maintains an e-commerce site that uses a Domino database to manage an online catalog of auto parts and tools. Acme carries parts from more than one vendor. Acme chose to use XML for this application because with XML as the common language to describe part information, a purchasing agent at Acme can pull information from various vendors about part pricing and availability directly into the Acme Auto Parts Catalog. Customers can access this application for up-to-date information about parts and tools from more than one distributor.

Creating a form that uses XML
You can use a form to enter 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. When you use XML elements on a form or page, you must follow the rules for constructing well-formed XML and you must properly format the XML tags. Additionally, the XML in a form or page should be accessed programmatically when using Microsoft Internet Explorer 5.5. Accessing pages or forms with XML in them directly will cause the browser to hang.

This step describes how to create the Parts form in the Acme Auto Parts Catalog.
Creating a view to display XML data
Now that you have a form to work with, you will need to create a view to display the XML documents. Views enable you to select which documents are rendered in XML and to track information. Views are also useful because they can deliver several documents at a time while a form can only deliver one document at a time. This step describes how to create a Parts view like the one in the Acme database.
Tip: If you have more than one element for a column, you can add a semicolon (;) at the end of the first column formula, and then add the column formula for the next element below it, as follows:

"<PARENT><CHILD>"+fieldname+"<\CHILD>";
"<CHILD>"+fieldname+"<\CHILD>";
"<CHILD>"+fieldname+"<\CHILD>"

Embedding a view in a page
Embedding a view in a page allows you to add the root element to your XML. Remember that the XML in a form or page should be accessed programmatically when using Microsoft Internet Explorer 5.5. Accessing pages or forms with XML in them directly will cause the browser to hang.

To embed the view in a page:
Accessing XML with LotusScript
Now that you have created a form, view, and page, you can access the XML you have created programmatically with LotusScript, JavaScript, or Java. Let's look at how to access XML using a server-side LotusScript agent. First, here's the agent:

Dim source As Variant

‘The sourceFile variable can be a URL, a file on the server, or a Notes
'document. If you want to access a specific document, you can use the
'OpenDocument URL command and the UNID of the document you want
'to access. For example, http://localhost/Acme.nsf/unid/OpenDocument
'where unid is the UNID of the document.
'sourceFile="http://localhost/Acme.nsf/GetParts?OpenPage"

‘This line creates the Microsoft.XMLDOM object.
Set source = CreateObject("Microsoft.XMLDOM")
source.async = False

‘This line loads the XML into the parser.
source.load(sourceFile)

'This line prevents Domino from sending default headers.
Print "Content-type: text/xml"

'This line displays the resulting XML in the browser.
Print source.xml

In order to make this agent accessible from a browser, you can add an action entry to the database outline. To see an example of this, be sure to download the Acme.nsf and Zippy.nsf databases from the Iris Sandbox on Notes.net. The Acme database runs this agent from the Parts (server-side LS) outline entry.

Here's how to add the agent to the Acme database outline:
Applying an XSL stylesheet to form data
Up to this point, you've seen that XML only describes data and doesn't define its appearance. The presentation is not important for computer-to-computer transactions, but if you're presenting data to a person, a stylesheet can help to make it more readable. A stylesheet can also determine which parts of the data are displayed and whether or not the data is converted to HTML, or to another form of XML. 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:
The Acme Auto Parts Catalog uses XSL to translate XML documents into HTML. The stylesheet, acmepartscatalog.xsl, appears below. Comment lines (indicated by <!-- and -->) explain the styles used in the stylesheet.

Note: The XSL standard used by IE 5.5 is different from the standard recommended by the W3C. Stylesheets created to work in earlier versions of IE 5.5 may not work with future versions of the parser and XSL processor.

<?xml version="1.0"?>

<!--This line is for IE only-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">

<!--root node-->
<xsl:template match="/" >

<!--This line sets the table border to 3 pixels, inset, black-->
<TABLE STYLE="border:3px inset black">

<!--The first row of the table. The font of the text in this row is set 10 point, boldface, Verdana, and the background color of the row to light grey.-->
<TR STYLE="font-size:10pt; background-color: lightgrey; font-family:Verdana; font-weight:bold">

<!--This is the text that will appear in the first cell of the first row of the table. All of the cells in this row will have the attributes defined in the line above.-->
<TD>Part Name</TD>

<!--This is the text that will appear in the second cell of the first row of the table-->
<TD>Part Number</TD>

<!--This is the text that will appear in the third cell of the first row of the table.-->
<TD>Manufacturer</TD>

<!--This is the text that will appear in the fourth cell of the first row of the table.-->
<TD>Stock</TD>

<!--This is the text that will appear in the fifth cell of the first row of the table.-->
<TD>Regular Price</TD>

<!--This is the text that will appear in the sixth cell of the first row of the table.-->
<TD>Sale Price</TD>

<!--The end of the first row in the table.-->
</TR>

<!--This line applies the defined style to the data in each child element contained by the root element <partscatalog> and the parent element <part>, then puts it in the table in order by part name. Note that order-by is not the field name, but the XML tag that is associated with the field.-->
<xsl:for-each select="partscatalog/part" order-by="partname">

<!--The second row and subsequent rows of the table. The font is set to Verdana, 10 point. The cell padding is set to 0 pixels and 6 pixels.-->
<TR STYLE="font-family:Verdana; font-size:10pt; padding:0px 6px">

<!--The data contained by the <partname> tag will be placed in the first column.-->
<TD><xsl:value-of select="partname" /></TD>

<!--The data contained by the <partnumber> tag will be placed in the second column.-->
<TD><xsl:value-of select="partnumber" /></TD>

<!--The data contained by the <manufacturer> tag will be placed in the third column.-->
<TD><xsl:value-of select="manufacturer" /></TD>

<!--The data contained by the <stock> tag will be placed in the fourth column.-->
<TD><xsl:value-of select="stock" /></TD>

<!--This line puts the data contained by the <regprice> tag in the fifth column. A dollar sign ($) will appear in each cell in the
fifth column before the price data.-->
<TD>$<xsl:value-of select="regprice" /></TD>

<!--The data contained by the sale price tag will be placed in the sixth column. A dollar sign ($) will appear in each cell in the sixth column before the price data. The background color of the cell is set to light grey.-->
<TD STYLE="background-color:lightgrey">$
<xsl:value-of select="saleprice" /></TD>

<!--This line ends each row of the table. Note that a third row, fourth row, and so on will be created until all of the data has been rendered.-->
</TR>

</xsl:for-each>

</TABLE>

</xsl:template>

</xsl:stylesheet>

To use an XSL stylesheet in a Domino application:
Accessing XML with JavaScript
The JavaScriptXML page in the Acme.nsf database uses client-side JavaScript to access the XML in the GetParts page and apply the acmepartscatalog.xsl stylesheet to it.

To access XML with client-side JavaScript: 9. In the OnLoad event, type or paste the following JavaScript: 10. Save the page.

11. Choose Design - Preview In Web Browser - Internet Explorer.
Note: You are able to preview this page directly in Internet Explorer 5.5 because the XML in the GetParts page is being accessed programmatically via JavaScript.

preview of the page

Exporting and generating XML using a Java agent
You can use Java to export and generate XML from a Notes document as well. For this example, you will need the IBM XML4J parser and the LotusXSL processor.

To install the IBM XML4j parser and the LotusXSL processor:


The Acme.nsf database uses the JavaAgent agent to get the XML data in the Parts page.

To export data and generate XML using a Java agent:
To access the Java agent from the browser:
Accessing information in another database
In this example, Acme wants to include information about parts that are supplied by Zippy Auto, an affiliate of Acme. Zippy maintains its own regional catalog with basically the same design as Acme's, but it's in a Domino database with no XML tags. You can write an agent that will retrieve the information from Zippy's database and display it for the client.

To create a LotusScript agent to access information in another database:
The following LotusScript code demonstrates how to get the information and transform it into XML. Note that the print statement will print the information to the status bar if the agent is run in the Notes client. If the agent is run in the browser, it will print to a page in the frameset.

Dim session As New NotesSession
'db is the current database
Dim db As NotesDatabase
'dbZippy is the database you want to access
Dim dbZippy As New NotesDatabase("","zippy.nsf")
Dim doc As NotesDocument
Dim view As NotesView

Set db = session.CurrentDatabase
'gets the Notes Documents view in Zippy's database
Set view = dbZippy.GetView( "Notes Documents" )
'gets the first document in the Notes Documents view
Set doc = view.GetFirstDocument

'prevents Domino from sending default headers
Print "Content-type: text/xml"
'this is the XML declaration
Print "<?xml version='1.0' encoding='UTF-8'?>"
'this is the XSL processing instruction
Print "<?xml:stylesheet type='text/xsl' href='acmepartscatalog.xsl' ?>"
'root element
Print "<partscatalog>"

'loop as long as there are document objects available
While Not ( doc Is Nothing )

'send the parent element for each parts document
Print "<part>"
Wend
'close the root element tag
Print "</partscatalog>"

Make this agent accessible from the browser by adding an action entry to the database outline. The Acme database runs this agent from the Zippy Tools outline entry.

To add the action to the Acme database outline:
Conclusion
Domino Designer provides an opportunity to integrate XML into Domino applications that share data across a network in a secure manner. You can add XML tags to forms and use views to determine which documents are rendered in XML. You can use stylesheets to create the look you want for your data. Agents are used to access XML in pages and forms, generate XML from non-XML documents, and retrieve data from other Domino applications. Hopefully, this article has provided you with some ideas about using XML in your own applications.


ABOUT THE AUTHOR
Prior her current position as a technical writer at IBM, Kyla was a member of the Domino Designer documentation team at Lotus for two years. While at Lotus, she worked on the Application Development with Domino Designer and the Domino Designer Programming Guide manuals. When she isn't writing, Kyla enjoys knitting, crocheting, and watching one of her four cats chase the yarn as she works.