This isn't a very common scenario, but every now and then the need arises to programmatically populate an Infopath form (from scratch) with data. After preparing the data in the required schema, my first thought was to do a simple “ThisXDocument.DOM.loadXML(strMyData)”. However that call triggers a “the DOM can’t be loaded twice” error. Another way would be to copy or write the data node-by-node into the DOM. This is generally a bad idea since it is complex, too much work to code/debug and worst of all – horribly slow! After a bit of experimentation I came up with the following which is simpler and blazing fast:
IXMLDOMDocument tmpDOM = thisXDocument.CreateDOM();tmpDOM.loadXML(strMyData);thisXDocument.ImportDOM(tmpDOM);
I thought I'd mention it since Google could find very little on InfoPath ImportDom.