Using XML with LotusScript

The following LotusScript classes process XML:

  • NotesXMLProcessor is a base class that contains properties and methods common to all XML classes.
  • NotesDXLExporter and NotesDXLImporter convert data between Domino and DXL (Domino XML).
  • NotesXSLTransformer transforms DXL through XSLT.
  • NotesDOMParser parses XML into a standard DOM (Document Object Model) tree. Additional NotesDOM classes allow you to work with DOM trees.
  • NotesSAXParser processes XML as events using a SAX (Simple API for XML) parser.

The following "helper" classes are useful in processing XML:

  • NotesStream streams XML to or from a memory buffer or file.
  • NotesNoteCollection builds subsets of Domino databases for NotesDXLExporter.

Use pipelining to move data from one processor to another.

Note: The COM interface:

  • Supports only NotesDXLExporter, NotesDXLImporter, NotesStream, and NotesNoteCollection.
  • Does not support pipelining.
  • Implements the ExitOnFirstFatalError, Log, and LogComment properties directly in NotesDXLExporter and NotesDXLImporter.
  • Implements Export in DXLExporter and Import in DXLImporter in place of Process, SetInput, SetOutput, and the parameters to CreateDXLExporter and CreateDXLImporter.

NotesXMLProcessor base class

The NotesXMLProcessor class is a base class for the LotusScript classes that process XML. You do not use the class directly but its properties and methods are available to the other XML classes.

The NotesXMLProcessor properties are:

  • ExitOnFirstFatalError (read-write, Boolean) terminates processing on a fatal error if True.
  • Log (read-only, String) contains errors generated by the processor.
  • LogComment (read-write, String) is a comment that is added to the beginning of the log.

The NotesXMLProcessor methods are:

  • SetInput specifies the input for the XML process.
  • SetOutput specifies the output for the XML process.
  • Process initiates an XML data conversion.

Where multiple XML processes use only the base properties and methods, you can simplify your program by using one subroutine. For example, you might code one subroutine that initiates processing then examines the log. Each time you call the subroutine, you specify as a parameter the pertinent XML object.

Pipelining

Pipelining allows you to combine operations so that the output of one XML process becomes the input to another XML process. For example, you may want to export Domino data as DXL, convert the DXL to a well known XML vocabulary, then apply a standard application that converts the XML to HTML. Each process feeds into the next. Rather than storing intermediate results, pipelining can be employed.

The XML processors require identification of the input and output prior to processing. You identify input and output when you create the XML object or later with SetInput and SetOutput. You initiate processing with Process.

To pipeline, specify input or output as an XML processor. For example, if you want exported DXL to feed into DOM processing, specify the output of the NotesDXLExporter object to be the NotesDOMParser object, or the input of the NotesDOMParser object to be the NotesDXLExporter object. Identify input and output for all objects in a pipeline before initiating processing. Initiating processing for the first processor in a pipeline initiates processing for all the processors.

A simple way to set up a pipeline is to identify only the input for all processors in the pipeline except the last. For the last processor, identify the input and the output.

The following table specifies allowable input and output for the XML processors.

Processor Possible input objects Possible output objects

NotesDXLExporter

NotesDatabase

NotesDocument

NotesDocumentCollection

NotesNoteCollection

NotesStream

NotesRichTextItem

NotesDXLImporter

NotesDOMParser

NotesSAXParser

NotesXSLTransformer

NotesDXLImporter

String

NotesStream

NotesRichTextItem

NotesDXLExporter

NotesDOMParser

NotesSAXParser

NotesXSLTransformer

NotesDatabase

NotesDOMParser

NotesSAXParser

NotesXSLTransformer

String

NotesStream

NotesRichTextItem

NotesDXLExporter

NotesDOMParser

NotesSaxParser

NotesXSLTransformer

NotesStream

NotesRichTextItem

NotesDXLImporter

NotesDOMParser

NotesSAXParser

NotesXSLTransformer

Export and import DXL

The NotesDXLExporter class converts Domino data to DXL. Use the CreateDXLExporter method in NotesSession to create a NotesDXLExporter object. Input to an export process can be a NotesDatabase, NotesDocument, NotesDocumentCollection, or NotesNoteCollection object. Output can be a NotesStream or NotesRichTextItem object, or any of the other XML processors.

To initiate an export, use Process or Export (no pipelining).

The NotesDXLExporter class has the following properties:

Property Data type Description

ConvertNotesBitmapsToGIF

Boolean

(Read-write) True to convert Domino bit maps to GIF format.

DoctypeSYSTEM

String

(Read-write) The value of SYSTEM in the !DOCTYPE statement.

ForceNoteFormat

Boolean

(Read-write) False to export formatted DXL.

OutputDOCTYPE

Boolean

(Read-write) False to suppress the !DOCTYPE statement.

SchemaLocation

String

(Read-write) The URI of the schema for the DXL being exported.

ValidationStyle

Integer

(Read-write) The method for validating the DXL being exported.

The NotesDXLImporter class converts DXL to Domino data. Use the CreateDXLImporter method in NotesSession to create a NotesDXLImporter object. Input to an import process can be a string, a NotesStream or NotesRichTextItem object, or any of the other XML processors. Output is a NotesDatabase object.

The import process constructs a list of note IDs for the newly imported notes. You can access these note IDs using the GetFirstNoteId and GetNextNoteId methods.

To initiate an import, use Process or Import (no pipelining).

The NotesDXLImporter class has the following properties:

Property Data type Description

ACLImportOption

Integer

(Read-write) Indicates the handling of incoming ACL entries.

CreateFTIndex

Boolean

(Read-write) Indicates whether the target database is full-text indexed.

DesignImportOption

Integer

(Read-write) Indicates the handling of incoming design elements.

DocumentImportOption

Integer

(Read-write) Indicates the handling of incoming documents.

ImportedNoteCount property

Long

(Read-only) The number of notes imported.

InputValidationOption

Integer

(Read-write) Indicates whether a DTD specified in the XML declaration statement should be used to validate the input XML.

ReplaceDbProperties

Boolean

(Read-write) True replaces the database properties from the DXL.

ReplicaRequiredForReplaceOrUpdate

Boolean

(Read-write) True requires that the replica ID of the DXL and the target database match.

NotesDXLImporter class

Integer

(Read-write) Indicates error logging options.

Transform DXL data through XSLT

To transform DXL data through XSLT:

  • Use the CreateXSLTransformer method in NotesSession to create a NotesXSLTransformer object.
  • Use the input parameter of CreateXSLTransformer or Transform, or theSetInput method to specify the input DXL data.
  • Use the output parameter of CreateXSLTransformer, the return value of Transform, or the SetOutput method to specify the output DXL data.
  • Use the styleSheet parameter of CreateXSLTransformer or Transform, or the SetStyleSheet method to specify the XSL style sheet.
  • Use Process or Transform to initiate the transformation.
  • Use the AddParameter method to add a parameter.

The NotesXSLTransformer class has the following properties:

Property Data type Description

InputValidationOption

Integer

(Read-write) Indicates that if a DTD is specified in the XML declaration statement, it should be used to validate the input XML.

Parse XML data into a DOM tree structure

To parse XML into a standard DOM tree structure of InputValidationOption objects:

  • Use the CreateDOMParser method in NotesSession to create a NotesDOMParser object.
  • Use the input parameter of CreateDOMParser or Parse, or the SetInput method to specify the input XML data.
  • Use the output parameter of CreateDOMParser or Parse, or the SetOutput method to specify the output XML data.
  • Use Process or Parse to parse the input XML into a DOM tree and then raise the PostDOMParse event.
  • Use the Output method to put text to the specified output object.
  • Use the Serialize method to copy the resulting XML to the DOM parser's output object.

The NotesDOMParser class has the following event:

Event Description

PostDOMParse

Called by the Process or Parse method to enable the use of the DOM parser in a pipeline of XML processors.

The NotesDOMParser class has the following properties:

Property Data type Description

AddXMLDeclNode

Boolean

(Read-write) Indicates that attributes from the XML declaration line -- version, encoding, and standalone attributes -- should be included in the resulting DOM tree in a NotesDOMXMLDeclNode object.

Document

NotesDOMDocumentNode

(Read-only) The root document of the DOM tree.

DoNamespaces

Boolean

(Read-write) Indicates that namespaces should be validated.

ExpandEntityReferences

Boolean

(Read-write) Indicates that every reference within a text value to an entity should be replaced by the entity's corresponding text value.

InputValidationOption

Integer

(Read-write) Indicates that if a DTD is specified in the XML declaration statement, it should be used to validate the input XML.

Access the DOM tree data using these methods of the specific NotesDOMNode classes.

  • AppendChild method
  • Clone method
  • RemoveChild method
  • ReplaceChild method

Parse XML data as a series of events

To parse XML using a SAX parser:

  • Use the CreateSAXParser method in NotesSession to create a NotesSAXParser object.
  • Use the input parameter of CreateSAXParser or Parse, or the SetInput method to specify the input XML data.
  • Use the output parameter of CreateSAXParser or Parse, or the SetOutput method to specify the output XML data.
  • Use Process or Parse to initiate the parsing.
  • Use the Output method to put text to the specified output.

The NotesSAXParser class has the following events:

Event Description

SAX Characters

Signals the occurrence of text in the input XML.

SAX EndDocument

Signals the end of the input XML.

SAX EndElement

Signals the end of the specified element in the input XML.

SAX Error

Signals that an error occurred when processing the input XML.

SAX FatalError

Signals that a fatal error occurred when processing the input XML.

SAX IgnorableWhiteSpace

Signals ignorable white space found in the input XML.

NotationDecl

Signals a notation declaration found in the input XML.

SAX ProcessingInstruction

Signals a processing instruction found in the input XML.

SAX ResolveEntity

Signals an entity found in the input XML.

SAX StartDocument

Signals the beginning of the input XML.

SAX StartElement

Signals the start of a special element in the input XML.

UnparsedEntityDecl

Signals an unparsed external entity declaration found in the input XML.

SAX Warning

Signals that a warning occurred when processing the input XML.

The NotesSAXParser class has the following property:

Property Data type Description

Input Validation Option

Integer

(Read-write) Indicates that, if a DTD is specified in the XML declaration statement, it should be used to validate the input XML.