<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://www.infopathdev.com:443/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Code</title><link>https://www.infopathdev.com:443/forums/45.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2007 SP3 (Build: 31118.962)</generator><item><title>Re: Insert a new XML node using a button control</title><link>https://www.infopathdev.com:443/forums/thread/13306.aspx</link><pubDate>Fri, 01 Jul 2005 23:01:31 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:13306</guid><dc:creator>mmelonis</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/13306.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=13306</wfw:commentRss><description>Thanks Scott. It worked;)&lt;br /&gt;&lt;br /&gt;Here is what my new code looks (primary additions in blue and a bunch of code deleted):&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public void CTRL1470_6_OnClick(DocActionEvent e)&lt;br /&gt;{&lt;br /&gt;	// Write your code here.&lt;br /&gt;	Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMDocument2 userViewDOM;&lt;br /&gt;	Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode newDataNode;&lt;br /&gt;	Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNodeList cpNodeList;&lt;br /&gt;	string childRef;&lt;br /&gt;&lt;br /&gt;	// Get a copy of DOM currently displayed to the user.&lt;br /&gt;	userViewDOM = (IXMLDOMDocument2)thisXDocument.DOM;&lt;br /&gt;&lt;br /&gt;	// Insert new Node.&lt;br /&gt;	childRef = "//ns1:Customer/ns1:Order"; &lt;br /&gt;&lt;br /&gt;	// In the file view.xsf, the parameter for ExecuteAction can be found:&lt;br /&gt;	// 1) In section properties make sure "Show insert button" is turned on&lt;br /&gt;	// 2) in view.xsf :&lt;br /&gt;	//		xd:xmlToEdit="Order_197" &lt;br /&gt;	//		xd:action="xCollection::insert" &lt;br /&gt;	// 3) The values above are the parameters for ExecuteAction.&lt;br /&gt;	// 4) In this example, after the fact I turned off "Show insert button"&lt;br /&gt;	//		and the ExecuteAction continued to work.&lt;br /&gt;	&lt;font color="blue"&gt;thisXDocument.View.ExecuteAction("xCollection::insert", "Order_197");&lt;br /&gt;	cpNodeList = thisXDocument.DOM.selectNodes(childRef);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;	// Find the new Order node.&lt;br /&gt;	int i;&lt;br /&gt;	for( i = 0; i &amp;lt;cpNodeList.length; i++)&lt;br /&gt;	{&lt;br /&gt;		if(cpNodeList&lt;i&gt;.selectSingleNode(".//ns1:OrderID").text == "")&lt;br /&gt;		{&lt;br /&gt;			break;&lt;br /&gt;		}&lt;br /&gt;	}&lt;br /&gt;	newDataNode = cpNodeList&lt;i&gt;;&lt;/font id="blue"&gt;&lt;br /&gt;	// Preset values.&lt;br /&gt;	newDataNode.selectSingleNode(".//ns1:CustomerID").text =&lt;br /&gt;        newDataNode.parentNode.selectSingleNode("//ns1:Customer/nsi:CustomerID".text;&lt;br /&gt;	newDataNode.selectSingleNode(".//ns1:OrderDate").text = DateTime.Now;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;</description></item><item><title>Re: Insert a new XML node using a button control</title><link>https://www.infopathdev.com:443/forums/thread/13305.aspx</link><pubDate>Fri, 01 Jul 2005 08:15:19 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:13305</guid><dc:creator>ScottAtRVC</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/13305.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=13305</wfw:commentRss><description>Hi.  Does this help &lt;a href='http://www.infopathdev.com/forums/topic.asp?TOPIC_ID=477' target='_blank' title='http://www.infopathdev.com/forums/topic.asp?TOPIC_ID=477'&lt;a target="_blank" href=http://www.infopathdev.com/forums/topic.asp?TOPIC_ID=477&gt;http://www.infopathdev.com/forums/topic.asp?TOPIC_ID=477&lt;/a&gt;&lt;/a&gt;  Cheers.  Scott.</description></item><item><title>Insert a new XML node using a button control</title><link>https://www.infopathdev.com:443/forums/thread/12478.aspx</link><pubDate>Wed, 29 Jun 2005 00:27:29 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:12478</guid><dc:creator>mmelonis</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/12478.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=12478</wfw:commentRss><description>I have an order entry form where the main data sources was provided via an established web services. The .xsd used by InfoPath is shown below as 'Abbreviated XML'. What I want is a button that will insert a new order record based on the xsd. Once the record is created, the code will pre-populated a few fields such as Order Date (and a few other fields not shown). &lt;br /&gt;&lt;br /&gt;The code I have written so far is shown below as 'Code Sample".&lt;br /&gt;&lt;br /&gt;The problem is the code only works if there is an existing Order Node. If a given customer has never created an order the code blows up, because their is not an existing Order node to clone. In other words, I want the Order structure to be an Optional, Repeating Table.&lt;br /&gt;&lt;br /&gt;I don't understand how to create a new Order Node using the predefined Order XML structure (defined by the XML). I've researched this for a while and it seems like it should be simple, but the solution is not obvious to me. Effectively what I don't understand is how to access/load a node from the Main Data source schema. All the examples that I've seen load the structure from a file.&lt;br /&gt;&lt;br /&gt;Any help would be much appreciated. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Abbreviate XML&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;xs:element name="Customer"&amp;gt;&lt;br /&gt;   &amp;lt;xs:complexType&amp;gt;&lt;br /&gt;      &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;          &amp;lt;xs:element name="CustomerID" /&amp;gt;&lt;br /&gt;          &amp;lt;xs:element name="LastName" /&amp;gt;&lt;br /&gt;          &amp;lt;xs:element name="MiddleName" /&amp;gt;&lt;br /&gt;          &amp;lt;xs:element name="FirstName"  /&amp;gt;&lt;br /&gt;          &amp;lt;xs:element name="Order" minOccurs="0" maxOccurs="unbounded"&amp;gt;&lt;br /&gt;               &amp;lt;xs:complexType&amp;gt;&lt;br /&gt;                    &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;                         &amp;lt;xs:element name="OrderID"  /&amp;gt;&lt;br /&gt;                         &amp;lt;xs:element name="CustomerID" /&amp;gt;&lt;br /&gt;                         &amp;lt;xs:element name="ProductName"  /&amp;gt;&lt;br /&gt;                         &amp;lt;xs:element name="ProductNumber"  /&amp;gt;&lt;br /&gt;                         &amp;lt;xs:element name="OrderDate" /&amp;gt;&lt;br /&gt;                    &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;                &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;           &amp;lt;/xs:element&amp;gt;&lt;br /&gt;	&amp;lt;xs:element name="BillingDetail" minOccurs="0" maxOccurs="unbounded"&amp;gt;&lt;br /&gt;               &amp;lt;xs:complexType&amp;gt;&lt;br /&gt;                    &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;                         &amp;lt;xs:element name="BillingDetailID"  /&amp;gt;&lt;br /&gt;                         &amp;lt;xs:element name="CustomerID" /&amp;gt;&lt;br /&gt;                         &amp;lt;xs:element name="ETC...."  /&amp;gt;&lt;br /&gt;                    &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;                &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;           &amp;lt;/xs:element&amp;gt;&lt;br /&gt;        &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;    &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;&amp;lt;/xs:element&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Sample Code:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public void CTRL1470_6_OnClick(DocActionEvent e)&lt;br /&gt;{&lt;br /&gt;	// Write your code here.&lt;br /&gt;	Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMDocument2 userViewDOM;&lt;br /&gt;	Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode parentDataNode;&lt;br /&gt;	Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode newDataNode;&lt;br /&gt;	string parentRef, childRef;&lt;br /&gt;&lt;br /&gt;	userViewDOM = (IXMLDOMDocument2)thisXDocument.DOM;&lt;br /&gt;&lt;br /&gt;	// Get a copy of the parent node.&lt;br /&gt;	parentRef = "//ns1:Customer"; &lt;br /&gt;	parentDataNode = userViewDOM.selectSingleNode(parentRef);&lt;br /&gt;&lt;br /&gt;	// ?????? How do I create a new Order Node using the predefined Order XML &lt;br /&gt;        // ?????? structure (defined by the XML)?&lt;br /&gt;&lt;br /&gt;	// Clone the new node that will be added.&lt;br /&gt;	childRef = "//ns1:Customer/ns1:Order"; &lt;br /&gt;	newDataNode = CloneNode(userViewDOM, childRef); &lt;br /&gt;&lt;br /&gt;			&lt;br /&gt;	// Walk the parentDataNode looking for the spot to insert the &lt;br /&gt;	// new node. In our case, this will were Order is found.&lt;br /&gt;	Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode siblingNode;&lt;br /&gt;	siblingNode = parentDataNode.firstChild;&lt;br /&gt;	while(siblingNode != null)&lt;br /&gt;	{&lt;br /&gt;		if(siblingNode.baseName != null)&lt;br /&gt;		{&lt;br /&gt;			if(siblingNode.baseName == "Order")&lt;br /&gt;			{&lt;br /&gt;			     break;&lt;br /&gt;			}&lt;br /&gt;		}&lt;br /&gt;		siblingNode = siblingNode.nextSibling;&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	// Preset values.&lt;br /&gt;	newDataNode.selectSingleNode(".//ns1:CustomerID").text =&lt;br /&gt;               parentDataNode.selectSingleNode("//ns1:Customer/nsi:CustomerID".text;&lt;br /&gt;	newDataNode.selectSingleNode(".//ns1:OrderDate").text = DateTime.Now;&lt;br /&gt;&lt;br /&gt;			&lt;br /&gt;&lt;br /&gt;	// Insert new Node in parent node.&lt;br /&gt;	parentDataNode.insertBefore(newDataNode,siblingNode);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;</description></item></channel></rss>