Working with MSXML and System.Xml Using the InfoPath 2003 Object Model

Last modified: May 29, 2009

Applies to: InfoPath 2010 | InfoPath Forms Services | Office 2010 | SharePoint Server 2010 | Visual Studio | Visual Studio Tools for Microsoft Office

Form template projects that work with the InfoPath 2003 object model use Microsoft XML Core Services (MSXML) internally to work with XML. In managed code, it is often easier to use the XML support provided by the System.Xml namespace in the .NET Framework class library. MSXML and System.Xml cannot exchange objects natively, so whenever you need to pass XML data between InfoPath and other managed code, XML data needs to be converted. You can exchange XML data from System.Xml objects with InfoPath form code by using the techniques in this topic.

To use members of the System.Xml namespace in a managed code project that uses the InfoPath 2003 object model, you must add a reference to System.Xml on the .NET tab of the Add Reference dialog box in Microsoft Visual Studio Tools for Applications.


  • To view reference information about MSXML, see the MSXML SDK.

  • Members of the MSXML object model that are wrapped by the Microsoft.Office.Interop.InfoPath.SemiTrust namespace cannot be assigned to delegates in the form code of managed-code form templates.

  • If you update the code of your form template to use the object model provided by members of the Microsoft.Office.InfoPath namespace, System.Xml is used natively. However, when doing so, you must manually convert all of your code to use the new object model. To convert your form template to use the new object model, in the Programming category of the Form Options dialog box, click Upgrade OM.

The following code sample demonstrates how to load an entire XML DOM from System.Xml code using the InfoPath CreateDOM method and the members of Microsoft XML Core Services that are wrapped by members of the Microsoft.Office.Interop.InfoPath.SemiTrust namespace.

The following examples require a using or Imports directive for System.Xml in the declarations section of the form code module. Additionally, because the Load method of the XmlDocument class requires System.Security.Permissions.FileIOPermission, you must configure the security level of the form template as Full Trust using the Security and Trust category of the Form Options dialog box.

// Create a System.Xml XmlDocument and load an XML file.
XmlDocument doc = new XmlDocument();

// Create an MSXML DOM object.
IXMLDOMDocument newDoc = thisXDocument.CreateDOM();

// Load the DOM with the XML from the System.XML object.

The following code sample shows a function that demonstrates how to clone a single node from a System.Xml.XmlElement using the wrapped MSXML createNode method.

The following examples require a using or Imports directive for System.Xml in the declarations section of the form code module.

// This function takes a System.Xml XmlElement object and 
// an MSXML IXMLDOMDocument object, and returns an MSXML 
// IXMLDOMNode object that is a copy of the XmlElement object.
public IXMLDOMNode CloneSystemXmlElementToMsxml(
   XmlElement systemXmlElement, IXMLDOMDocument msxmlDocument)

   IXMLDOMNode msxmlResultNode;

   // Create a new element from the MSXML DOM using the same 
   // namespace as the XmlElement.
   msxmlResultNode = msxmlDocument.createNode(

   // Set the element's value.
   msxmlResultNode.text = systemXmlElement.Value.ToString();

   return msxmlResultNode;