Section 10.6.  The InfoPath object model

Prev don't be afraid of buying books Next

10.6. The InfoPath object model

Microsoft provides an object model for use in InfoPath scripts. The object model allows you to programmatically manipulate the underlying XML document, as well as the user interface itself. Figure 10-5 shows the basic hierarchy of the object model. Only the most commonly used objects are shown.

Figure 10-5. InfoPath object hierarchy




At the top of the object model hierarchy is the Application object which represents the application itself. From Application, you can access the open InfoPath windows via the Windows property, as well as the open XML documents, via the XDocuments property.

In most scripts you will be interested in performing some operation that involves the currently displayed XML document, which can be accessed via the XDocument object. For example, in 10.2, "A simple sample script", on page 228, we used the method call XDocument.UI.Alert to display a message box within the current document. The XDocument object has a number of properties that are useful in scripts:

  • DOM can be used to get an XML representation of the document. This is discussed further in the next section.

  • UI can be used to display message boxes and other dialogs.

  • View can be used to switch views, determine what view is currently displayed, and which fields are currently selected.

  • DataObjects can be used to access secondary data sources, which are described in 11.1, "Defining a secondary data source", on page 252.

In addition, there are event objects that are passed to scripts as parameters when an event, such as clicking a button or changing a value, occurs.

10.6.1 Using the XML document object model

Many scripts involve querying or manipulating the XML document behind the form. This is accomplished by accessing the DOM (Document Object Model) of the XML document. DOM is an open W3C standard model for accessing XML documents. Microsoft implements the W3C standard and also provides some convenient extensions.

DOM is made up of quite a large number of objects, and therefore cannot be covered in a single chapter. However, we will provide you with a series of examples for common use cases. You can browse the complete DOM object model using Script Editor, as described in the next section.

You can access the DOM for the currently displayed XML document by specifying XDocument.DOM. The XDocument.DOM property represents the document as a whole. From there, you can access the nodes of the document.

Nodes are elements, attributes and other XML constructs such as comments and processing instructions. In addition, the character data content of an element is considered a node, specifically a text node. Nodes are arranged in a hierarchy and may have children and parents.

Using the DOM, you can select nodes from the document using an XPath expression. Alternatively, you can traverse the document via the nodes and their parent/child relationships to retrieve the elements and attributes of interest. You can also use the DOM to update the value of existing nodes, and insert new ones. We will look at each of these uses in turn.

10.6.2 Browsing the object model

The InfoPath object model is fully documented in the InfoPath Developer's Reference, which is included in the InfoPath help. This document is a reference guide for the various events and objects and their associated properties and methods.

In addition, you can browse the InfoPath object model interactively in Script Editor using Object Browser. If Object Browser is not already displayed, point to Other Windows on the View menu, then click Object Browser.

In Object Browser, you can traverse the object model much as you might in Windows Explorer. When an object is selected in the left-hand pane, its members (functions and properties) are displayed to the right, as shown in Figure 10-6. The pane at the bottom of Object Browser displays further information about the component, often including a description of its purpose.

Figure 10-6. Object Browser




Amazon


XML in Office 2003. Information Sharing with Desktop XML
XML in Office 2003: Information Sharing with Desktop XML
ISBN: 013142193X
EAN: 2147483647
Year: 2003
Pages: 176

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net