XDocument Interface

Represents the underlying XML document of a form.

Namespace:  Microsoft.Office.Interop.InfoPath.SemiTrust
Assembly:  Microsoft.Office.Interop.InfoPath.SemiTrust (in Microsoft.Office.Interop.InfoPath.SemiTrust.dll)

Syntax

'Declaration
<GuidAttribute("096cd6a8-0786-11d1-95fa-0080c78ee3bb")> _
Public Interface XDocument _
    Inherits _XDocument2, _XDocument
'Usage
Dim instance As XDocument
[GuidAttribute("096cd6a8-0786-11d1-95fa-0080c78ee3bb")]
public interface XDocument : _XDocument2, 
    _XDocument

Remarks

This type is a wrapper for a coclass that is required by managed code for COM interoperability. Use this type to access the members of the COM interface implemented by this coclass. For information about the COM interface, including a link to descriptions of its members, see_XDocument2.

Using the members of the _XDocument2 interface provides compatibility with InfoPath 2003. To use new members that were added to the XDocument object model in Microsoft InfoPath 2010 such as the _XDocument3.Permission property, you must cast the XDocument object to the _XDocument3 type. For more information, see How to: Use Microsoft.Office.Interop.InfoPath.SemiTrust Members That Are Not Compatible with InfoPath 2003.

The XDocument object is a key object in the InfoPath object model that provides properties, methods, and events that can be used to programmatically interact with and manipulate the source XML data of a form.

While the XDocument object can be accessed using the XDocumentsCollection collection, in most cases you will access it from the thisXDocument variable that is instantiated in the _Startup method of a managed-code project without going through the collection.

The source XML data of a form takes the form of an XML Document Object Model (DOM), which is accessed through the DOM property. The XDocument object also provides a number of properties that can be used to get information about the form and its underlying XML document. It also provides a number of methods that can be used on the form, such as printing, saving, and submitting. The XDocument object also provides a number of events that can be used to respond to various actions that occur at the form level, such as loading of a form, switching views, or a merge operation.

Accessing the XDocument Object

The XDocument object can be accessed in a variety places within the InfoPath object model. The following table summarizes the locations where the XDocument object is available.

Name

Description

XDocumentsCollection

Accessed from Application. Provides Item for accessing the XDocument objects that it contains.

DataDOMEventObject

Provides XDocument for accessing the source XML data during an XML DOM change.

DocActionEventObject

Provides XDocument for accessing the source XML data during a button click in the form area.

DocEventObject

Provides XDocument for accessing the source XML data during a switch view or form merge operation.

DocReturnEventObject

Provides XDocument for accessing the source XML during the loading or submission of a form.

VersionUpgradeEventObject

Provides XDocument for accessing the source XML during the version upgrade operation.

WindowObject

Provides XDocument for accessing the XDocument object associated with the window.

Examples

The source XML data of a form takes the form of an XML Document Object Model (DOM), which is accessed through the DOM property of the XDocument object. The XDocument object also provides a number of properties that can be used to get information about the form and its underlying XML document. For example, the following code checks to see whether data in the form has been changed by using the IsDirty property:

if (thisXDocument.IsDirty)
{
   thisXDocument.UI.Alert("Form has been changed.");
}
else
{
   thisXDocument.UI.Alert("Form has not been changed.");
}

In addition to information about the form and its underlying XML document, the XDocument object provides a number of methods that can be used on the form, such as printing, saving, and submitting. It also provides a number of events that can be used to respond to various actions that occur at the form level, such as loading of a form, switching views, or a merge operation.

For another sample that demonstrates working with the XDocument object, see

How to: Access Application Data Using the InfoPath 2003 Object Model.

See Also

Reference

XDocument Members

Microsoft.Office.Interop.InfoPath.SemiTrust Namespace