Edit

Share via


_XDocument3.CreateDOM Method

Definition

Creates a new instance of the XML Document Object Model (DOM) in memory.

public:
 Microsoft::Office::Interop::InfoPath::Xml::IXMLDOMDocument ^ CreateDOM();
public Microsoft.Office.Interop.InfoPath.Xml.IXMLDOMDocument CreateDOM ();
abstract member CreateDOM : unit -> Microsoft.Office.Interop.InfoPath.Xml.IXMLDOMDocument
Public Function CreateDOM () As IXMLDOMDocument

Returns

An IXMLDOMDocument of the new instance of the XML Document Object Model (DOM).

Implements

Examples

// create a new XMLDOMDocument that can be used by InfoPath
IXMLDOMDocument newDOM = thisXDocument.<span class="label">CreateDOM</span>();
// Get one node from the main DOM and add it to the new DOM
IXMLDOMNode referenceNode = thisXDocument.DOM.selectSingleNode("//my:group1");
newDOM.appendChild(referenceNode);
// create a new node that will be added to the new DOM
IXMLDOMNode newNode = newDOM.createNode(1,"my:Group2",referenceNode.namespaceURI);
// Set its value
newNode.text = "this is a group2 node";
// Set the SelectionNamespaces attribute with the namespace used in the new DOM
((IXMLDOMDocument2)newDOM).setProperty("SelectionNamespaces","xmlns:my='" + referenceNode.namespaceURI + "'");
// Select one mode from the new DOM and add the new Node as its child
IXMLDOMNode parentNode = newDOM.selectSingleNode("//my:group1");
parentNode.appendChild(newNode);
// create a new XMLDOMDocument that can be used by InfoPath
IXMLDOMDocument newDOM = thisXDocument.<span class="label">CreateDOM</span>();
// Get one node from the main DOM and add it to the new DOM
IXMLDOMNode referenceNode = thisXDocument.DOM.selectSingleNode("//my:group1");
newDOM.appendChild(referenceNode);
// create a new node that will be added to the new DOM
IXMLDOMNode newNode = newDOM.createNode(1,"my:Group2",referenceNode.namespaceURI);
// Set its value
newNode.text = "this is a group2 node";
// Set the SelectionNamespaces attribute with the namespace used in the new DOM
((IXMLDOMDocument2)newDOM).setProperty("SelectionNamespaces","xmlns:my='" + referenceNode.namespaceURI + "'");
// Select one mode from the new DOM and add the new Node as its child
IXMLDOMNode parentNode = newDOM.selectSingleNode("//my:group1");
parentNode.appendChild(newNode);

Remarks

Using the CreateDOM method to create an instance of the XML DOM is equivalent to using the following method of creating a Microsoft XML Core Services (MSXML) 5.0 DOMDocument object:

var objDoc = new ActiveXObject("Msxml2.DOMDocument.5.0");

Note: When automating InfoPath, the setProperty method of the IXMLDOMDocument2 object may fail for secondary data sources. To use the setProperty method, follow this example:

IXMLDOMDocument2 myDocument = (IXMLDOMDocument2) thisXDocument.<span class="label">CreateDOM</span>();
myDocument.setProperty("SelectionNameSpaces",namespaceString);

Applies to