Represents the underlying XML document of a form.
Assembly: Microsoft.Office.InfoPath (in Microsoft.Office.InfoPath.dll)
The class is a key object in the InfoPath managed code object model that provides properties, methods, and events that can be used to programmatically interact with and manipulate the XML data in the underlying XML document of a form.
While objects can be accessed from the XmlFormCollection class using the XmlForms property of the Application class, in most cases, when working with form template business logic you will access the class and its members using the this (in C#) or Me (in Visual Basic) keywords without going through the collection.
For example, the following code examples of event handlers for the Loading event use the this or Me keywords to access the MainDataSource and NamespaceManager properties of the class. These properties are used to work with an instance of the System.Xml.XPath.XPathNavigator class to navigate to the employee field (resolving namespace prefixes by using the NamespaceManager property), and then set the field to the current user's username.
Public Sub FormEvents_Loading(ByVal sender As Object, ByVal e As LoadingEventArgs) ' Create XPathNavigator positioned at the root of the main data ' source. Dim myNav As XPathNavigator = Me.MainDataSource.CreateNavigator() ' Select employee field and set value to username. myNav.SelectSingleNode("//my:employee", Me.NamespaceManager). _ SetValue(System.Environment.UserName) End Sub
It is not necessary to explicitly reference the this or Me keywords to access the members of the class in form code. For example, the lines of code to access the MainDataSource property in the previous C# and Visual Basic examples can be written as follows:
XPathNavigator myNav = MainDataSource.CreateNavigator() Dim myNav As XPathNavigator = MainDataSource.CreateNavigator()
However, using the this or Me keywords when writing code does facilitate IntelliSense statement completion, which lists the members of the class when writing business logic code in a form template's FormCode module.
When working with managed code, the source XML data of a form is accessed through the MainDataSource property which returns an instance of the DataSource class that represents the main data source of the form. The CreateNavigator method of the DataSource class is then used to create an instance of the System.Xml.XPath.XPathNavigator class which is positioned at the root of the form's underlying XML document. The members of the XPathNavigator class can then be used to navigate, read from and write to the form data. For more information about using the XPathNavigator class in InfoPath form code, see How to: Work with the XPathNavigator and XPathNodeIterator Classes.
The class also provides additional properties that can be used to get information about the form and its underlying XML document. It also provides methods that can be used to perform various actions with the form, such as printing, saving, and submitting. Form-level events, such as loading a form, switching views, or a merge operation, are implemented by the FormEvents class. Additionally, events raised by changes to the underlying XML document itself are implemented by the XmlEvents class.
Provides the XmlForm property for accessing the object associated with the window.
In the InfoPath 2003 compatible managed code object model (the types and members of the Microsoft.Office.Interop.InfoPath.SemiTrust namespace), which was first introduced in InfoPath 2003 Service Pack 1 in conjunction with the Microsoft Office InfoPath 2003 Toolkit for Visual Studio .NET, the following classes provided an XDocument property for accessing the underlying XML document of a form during events: DataDOMEventObject, DocActionEventObject, DocEventObject, DocReturnEventObject, and VersionUpgradeEventObject classes.
In the new InfoPath managed code object model (the types and members of the Microsoft.Office.InfoPath namespace), you use the this (in C#) or Me (in Visual Basic) keywords to access the class and its members from event handlers and from other code in your form template business logic.