_XDocument3.CreateDOM 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
在内存中新建 XML 文档对象模型 (DOM) 实例。
public:
Microsoft::Office::Interop::InfoPath::SemiTrust::IXMLDOMDocument ^ CreateDOM();
public Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMDocument CreateDOM ();
abstract member CreateDOM : unit -> Microsoft.Office.Interop.InfoPath.SemiTrust.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);