_XDocument2.CreateDOM 方法

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

命名空间:  Microsoft.Office.Interop.InfoPath.SemiTrust
程序集:  Microsoft.Office.Interop.InfoPath.SemiTrust(位于 Microsoft.Office.Interop.InfoPath.SemiTrust.dll 中)

语法

声明
Function CreateDOM As IXMLDOMDocument
用法
Dim instance As _XDocument2
Dim returnValue As IXMLDOMDocument

returnValue = instance.CreateDOM()
IXMLDOMDocument CreateDOM()

返回值

类型:Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMDocument
XML 文档对象模型 (DOM) 的新实例的 IXMLDOMDocument。

备注

使用 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.CreateDOM();
myDocument.setProperty("SelectionNameSpaces",namespaceString);

示例

// create a new XMLDOMDocument that can be used by InfoPath
IXMLDOMDocument newDOM = thisXDocument.CreateDOM();
// 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);

另请参阅

引用

_XDocument2 接口

_XDocument2 成员

Microsoft.Office.Interop.InfoPath.SemiTrust 命名空间