_XDocument3.CreateDOM 方法

定义

在内存中新建 XML 文档对象模型 (DOM) 实例。

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

返回

XML 文档对象模型 (DOM) 的新实例的 IXMLDOMDocument

实现

示例

// 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);

注解

使用 CreateDOM 方法创建 XML DOM 实例等效于使用下列用来创建 Microsoft XML Core Services (MSXML) 5.0 DOMDocument 对象的方法:

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

注意:自动执行 InfoPath 时,对于辅助数据源,IXMLDOMDocument2 对象的 setProperty 方法可能会失败。 若要使用 setProperty 方法,可参照此示例:

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

适用于