We recommend using Visual Studio 2017

XmlForm.NamespaceManager Property

Gets a reference to a XmlNamespaceManager object that can be used to resolve, add, or remove namespaces used in the form.

Namespace: Microsoft.Office.InfoPath
Assembly: Microsoft.Office.InfoPath (in microsoft.office.infopath.dll)

Property Value

An XmlNamespaceManager that can be used resolve, add, or remove namespaces used in the form.

The XmlNamespaceManager object is initialized at load time with all the namespaces defined in the xDocumentClass element of the form template's form definition file (.xsf).

A developer can use the instance of the XmlNamespaceManager class to resolve, add, or remove namespaces from the form template. For browser-enabled forms, the class is persisted on the server. All namespaces added using the XmlNamespaceManager class are persisted in the session state of the form template so that they are available across all requests for the form.

This member can be accessed only by forms running in the same domain as the currently open form, or by forms that have been granted cross-domain permissions.

This type or member can be accessed from code running in forms opened in Microsoft Office InfoPath 2007 or in a Web browser.

In the following example, the NamespaceManager property is used to get an instance of the System.Xml.XmlNamespaceManager class that is then used to resolve namespaces when using the System.Xml.XPath.XPathNavigator.SelectSingleNode method to select a field.

public void FormEvents_Loading(object sender, LoadingEventArgs e)
   // Create XPathNavigator positioned at the root of the main data 
   // source.
   XPathNavigator myNav = this.MainDataSource.CreateNavigator()

   // Select employee field and set value to username.