Thank you very much guys.But I have a problem when using the same code as the one given by Frank
Case1The structure of my data source is as follows
--PR_Form //root
--Executers //This is a group
--Approvers //This is a group
---Approver //This is a
repeating group
--- ApproverName //Field
Now in the onclick event if I write the code given by Franck as follows..
IXMLDOMDocument2 templateDom = (IXMLDOMDocument2)thisXDocument.CreateDOM();
templateDom.validateOnParse = false;
templateDom.load("template.xml");
templateDom.setProperty("SelectionNamespaces", "xmlns:my='http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-11-02T09:58:08'");
IXMLDOMNode oTemplateGrp = templateDom.selectSingleNode("/my:PR_Form/my:Executers/my:Approvers/my:Approver");
IXMLDOMNode oTemplateNode = oTemplateGrp.cloneNode(true);
IXMLDOMNode oGroup1 = thisXDocument.DOM.selectSingleNode("/my:PR_Form/my:Executers/my:Approvers");
oGroup1.appendChild(oTemplateNode);But when debugging,after the last line i.e
"oGroup1.appendChild(oTemplateNode);",
Infopath throws an error stating
System.Runtime.InteropServices.COMException
Element 'http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-11-02T09:58:08}Approver' is unexpected according to content model of parent element 'http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-11-02T09:58:08}Approvers'.
at Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode.appendChild(IXMLDOMNode newChild)
at Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeWrapper.appendChild(IXMLDOMNode newChild)
at Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeWrapper.appendChild(IXMLDOMNode newChild)
at PR_Automation.PR_Automation.CTRL16_40_OnClick(DocActionEvent e) in e:\1pr_automation\pr_automation\formcode.cs:line 123
at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)
Out of curiosity,I used "templateDom.selectSingleNode" instead of "thisXDocument.Dom.selectSingleNode" when creating the oGroup1 node.Surprisingly Infopath did not throw the error nor did I get the desired results.
So I think its got something to do with setting namespace or some thing like that.
Need ur help guys.
Regards,
Abhishek