<?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: XPathNavigator.AppendChild() Replaces Instead of Appends</title><link>https://www.infopathdev.com:443/forums/thread/87681.aspx</link><pubDate>Tue, 05 Mar 2013 18:57:38 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:87681</guid><dc:creator>abcolson</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/87681.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=87681</wfw:commentRss><description>&lt;p&gt;Chalk this one up to me being stupid (sort of) ...&amp;nbsp;:|&lt;/p&gt;&lt;p&gt;In short, I had a Patient_Change event handler that was deleting the Isolations right when I was adding them.&amp;nbsp; Sounds crazy, right?&amp;nbsp; Well, let me explain since this might be biting someone else...&lt;/p&gt;&lt;p&gt;I was porting over an InfoPath 2003 form into InfoPath 2010. Sigh...as we all know everything changed in the guts of InfoPath; moving from IXMLDOMNode to XPathNavigator as well as ... &lt;em&gt;process behavior&lt;/em&gt;&lt;/p&gt;&lt;p&gt;When I was porting over the IP 2003 files I basically created the new IP 2010 project and then with the structure in place started copying over the .xsl and .cs files.&amp;nbsp; Of course, the .cs files didn&amp;#39;t even come close to compiling.&amp;nbsp; So, the first pass was to take care of all the syntax errors and make the obvious changes (like IXMLDOMNode to XPathNavigator, etc.).&amp;nbsp; In event handlers, this included adapting phrases like &lt;em&gt;if( e.Operation == &amp;quot;Insert&amp;quot; )&lt;/em&gt; to &lt;em&gt;if( e.Operation == XmlOperation.Insert )&lt;/em&gt;.&amp;nbsp; No big deal, except the function of the operation changed.&amp;nbsp; In IP 2003 the insertion of a child node did not trip the event handler of the parent(s) whereas (apparently) in IP 2010 is does.  So, what was happening was that a special insert situation in my parent (Patient) event handler (which worked fine in IP 2003) was now being tripped in IP 2010 when I inserted a child (Isolation) node.&amp;nbsp; I was able to deduce this by trying to programatically add multiple Patient nodes (which worked) and then adding in a repeating section into the GUI and trying to add multiple Isolations (which didn&amp;#39;t work and yeilded the same weird behavior in the initial post).&amp;nbsp; After observing this framework of behavior I started thinking of event handling and BAM!&amp;nbsp; I found the cause and fix as noted above.&amp;nbsp; Frustrating as @#$#@%$@ !!!&lt;/p&gt;&lt;p&gt;Hope this helps someone...&lt;/p&gt;&lt;p&gt;Tony&lt;/p&gt;&lt;font color="#a31515" size="2"&gt;&lt;font color="#a31515" size="2"&gt;&lt;/font&gt;&lt;/font&gt;</description></item><item><title>XPathNavigator.AppendChild() Replaces Instead of Appends</title><link>https://www.infopathdev.com:443/forums/thread/87636.aspx</link><pubDate>Mon, 04 Mar 2013 19:24:27 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:87636</guid><dc:creator>abcolson</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/87636.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=87636</wfw:commentRss><description>&lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;

Greetings,&lt;/font&gt;&lt;/p&gt;&lt;p&gt;I have encountered&amp;nbsp;some peculiar behavior which I can neither explain nor find referenced in the documentation.&amp;nbsp; I am using InfoPath 2010 on Windows 7 and am developing a C# form.&amp;nbsp; The structure of the&amp;nbsp;underlying data is something like:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&amp;lt;Submission&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Patient&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Isolation /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Patient&amp;gt;&lt;br /&gt;&amp;lt;/Submission&amp;gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;What I am attempting to do is programmatically add an Isolation to a Patient when a user clicks a button.&amp;nbsp;(For debugging purposes I have simulated this event in the &lt;font size="2"&gt;&lt;em&gt;FormEvents_Loading &lt;/em&gt;method to eliminate other factors...the results are the same.)&amp;nbsp; At present, the patient&amp;nbsp;initializes with&amp;nbsp;1 Isolation from the default template.&lt;/font&gt;&lt;/p&gt;&lt;p&gt;I can get an XPathNavigator to a&amp;nbsp;Patient just fine, and even inspect and change attributes if I please.&amp;nbsp; When it comes time to call AppendChild() to add an Isolation I make sure the NodeType is Element and then call AppendChild().&amp;nbsp; Now, in the absence of any exceptions, I would expect a new Isolation to be created and added under Patient; but alas, this is not the case.&amp;nbsp; What appears to be happening is that the new Isolation is created but instead of &lt;em&gt;appending&lt;/em&gt; to the list of Isolations in Patient, the original Isolation from the default&amp;nbsp;template is &lt;em&gt;replaced&lt;/em&gt; with the new one.&amp;nbsp; I can find no documentation regarding this behavior whether it be about methodologies for calling AppendChild() or invalid states of XPathNavigators where the method does nothing.&amp;nbsp; So, does anyone have an idea on what could be happening?&lt;/p&gt;&lt;p&gt;Below is some code which shows what I am doing.&amp;nbsp; I have tried using various overloads of AppendChild(); this example just shows one case:&lt;/p&gt;&lt;blockquote&gt;&lt;p style="margin:0in 0in 0pt;line-height:normal;mso-background-themecolor:background2;mso-background-themeshade:230;mso-layout-grid-align:none;" class="MsoNormal"&gt;&lt;span style="color:blue;font-size:10pt;mso-no-proof:yes;"&gt;const&lt;/span&gt;&lt;span style="font-size:10pt;mso-no-proof:yes;"&gt; &lt;span style="color:blue;"&gt;string&lt;/span&gt; ATTR_1 = NODE_NAME_PATIENT_ISOLATIONS_PATIENT;&lt;br /&gt;&lt;/span&gt;&lt;span style="color:blue;font-size:10pt;mso-no-proof:yes;"&gt;const&lt;/span&gt;&lt;span style="font-size:10pt;mso-no-proof:yes;"&gt; &lt;span style="color:blue;"&gt;string&lt;/span&gt; ATTR_2 =
NODE_NAME_PATIENT_ISOLATIONS_ISOLATION;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0in 0in 0pt;line-height:normal;mso-background-themecolor:background2;mso-background-themeshade:230;mso-layout-grid-align:none;" class="MsoNormal"&gt;&lt;span style="font-size:10pt;mso-no-proof:yes;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0in 0in 0pt;line-height:normal;mso-background-themecolor:background2;mso-background-themeshade:230;mso-layout-grid-align:none;" class="MsoNormal"&gt;&lt;span style="font-size:10pt;mso-no-proof:yes;"&gt;&lt;/span&gt;&lt;span style="color:blue;font-size:10pt;mso-no-proof:yes;"&gt;for&lt;/span&gt;&lt;span style="font-size:10pt;mso-no-proof:yes;"&gt; (&lt;span style="color:blue;"&gt;int&lt;/span&gt; i = 1; i &amp;lt;= 2; i++)&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0in 0in 0pt;line-height:normal;mso-background-themecolor:background2;mso-background-themeshade:230;mso-layout-grid-align:none;" class="MsoNormal"&gt;&lt;span style="font-size:10pt;mso-no-proof:yes;"&gt;&lt;/span&gt;&lt;span style="font-size:10pt;mso-no-proof:yes;"&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0in 0in 0pt;line-height:normal;mso-background-themecolor:background2;mso-background-themeshade:230;mso-layout-grid-align:none;" class="MsoNormal"&gt;&lt;span style="font-size:10pt;mso-no-proof:yes;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;mso-no-proof:yes;"&gt;&lt;span style="color:blue;"&gt;string&lt;/span&gt;
localName = NODE_NAME_PATIENT_ISOLATIONS.Substring(2);&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0in 0in 0pt;line-height:normal;mso-background-themecolor:background2;mso-background-themeshade:230;mso-layout-grid-align:none;" class="MsoNormal"&gt;&lt;span style="font-size:10pt;mso-no-proof:yes;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;mso-no-proof:yes;"&gt;XmlDocument&lt;/span&gt;&lt;span style="font-size:10pt;mso-no-proof:yes;"&gt; doc = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span&gt;XmlDocument&lt;/span&gt;();&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0in 0in 0pt;line-height:normal;mso-background-themecolor:background2;mso-background-themeshade:230;mso-layout-grid-align:none;" class="MsoNormal"&gt;&lt;span style="font-size:10pt;mso-no-proof:yes;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size:10pt;mso-no-proof:yes;"&gt;&lt;span&gt;XmlElement&lt;/span&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;ele = doc.CreateElement(DATA_PREFIX,
localName, DATA_NAMESPACE);&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0in 0in 0pt;line-height:normal;mso-background-themecolor:background2;mso-background-themeshade:230;mso-layout-grid-align:none;" class="MsoNormal"&gt;&lt;span style="font-size:10pt;mso-no-proof:yes;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0in 0in 0pt;line-height:normal;mso-background-themecolor:background2;mso-background-themeshade:230;mso-layout-grid-align:none;" class="MsoNormal"&gt;&lt;span style="font-size:10pt;mso-no-proof:yes;"&gt;&lt;/span&gt;&lt;span style="font-size:10pt;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;ele.Attributes.Append(doc.CreateAttribute(ATTR_1));&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0in 0in 0pt;line-height:normal;mso-background-themecolor:background2;mso-background-themeshade:230;mso-layout-grid-align:none;" class="MsoNormal"&gt;&lt;span style="font-size:10pt;mso-no-proof:yes;"&gt;&lt;/span&gt;&lt;span style="font-size:10pt;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;ele.Attributes.Append(doc.CreateAttribute(ATTR_2));&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0in 0in 0pt;line-height:normal;mso-background-themecolor:background2;mso-background-themeshade:230;mso-layout-grid-align:none;" class="MsoNormal"&gt;&lt;span style="font-size:10pt;mso-no-proof:yes;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0in 0in 0pt;line-height:normal;mso-background-themecolor:background2;mso-background-themeshade:230;mso-layout-grid-align:none;" class="MsoNormal"&gt;&lt;span style="font-size:10pt;mso-no-proof:yes;"&gt;&lt;/span&gt;&lt;span style="font-size:10pt;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;if&lt;/span&gt;( i == 1 )
ele.SetAttribute(ATTR_1, &lt;span&gt;&amp;quot;99&amp;quot;&lt;/span&gt;);&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0in 0in 0pt;line-height:normal;mso-background-themecolor:background2;mso-background-themeshade:230;mso-layout-grid-align:none;" class="MsoNormal"&gt;&lt;span style="font-size:10pt;mso-no-proof:yes;"&gt;&lt;/span&gt;&lt;span style="font-size:10pt;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;ele.SetAttribute(ATTR_2, i.ToString());&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0in 0in 0pt;line-height:normal;mso-background-themecolor:background2;mso-background-themeshade:230;mso-layout-grid-align:none;" class="MsoNormal"&gt;&lt;span style="font-size:10pt;mso-no-proof:yes;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0in 0in 0pt;line-height:normal;mso-background-themecolor:background2;mso-background-themeshade:230;mso-layout-grid-align:none;" class="MsoNormal"&gt;&lt;span style="font-size:10pt;mso-no-proof:yes;"&gt;&lt;/span&gt;&lt;span style="font-size:10pt;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span&gt;XPathNavigator&lt;/span&gt;
n1 = ele.CreateNavigator();&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0in 0in 0pt;line-height:normal;mso-background-themecolor:background2;mso-background-themeshade:230;mso-layout-grid-align:none;" class="MsoNormal"&gt;&lt;span style="font-size:10pt;mso-no-proof:yes;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;&lt;span style="font-size:10pt;mso-no-proof:yes;"&gt;&lt;/span&gt;&lt;span style="font-size:10pt;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&lt;p style="margin:0in 0in 0pt;line-height:normal;mso-background-themecolor:background2;mso-background-themeshade:230;mso-layout-grid-align:none;" class="MsoNormal"&gt;&lt;span style="font-size:10pt;mso-no-proof:yes;"&gt;&lt;/span&gt;&lt;span style="font-size:10pt;mso-no-proof:yes;"&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;&amp;nbsp; if&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; (patient.NodeType != &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;XPathNodeType&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;.Element) patient.MoveToParent();&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0in 0in 0pt;line-height:normal;mso-background-themecolor:background2;mso-background-themeshade:230;mso-layout-grid-align:none;" class="MsoNormal"&gt;&lt;font size="2"&gt;&lt;/font&gt;&amp;nbsp;&lt;/p&gt;&lt;/span&gt;&lt;p style="margin:0in 0in 0pt;line-height:normal;mso-background-themecolor:background2;mso-background-themeshade:230;mso-layout-grid-align:none;" class="MsoNormal"&gt;&amp;nbsp;&amp;nbsp;patient.AppendChild(n1);&lt;/p&gt;&lt;/span&gt;&lt;p style="margin:0in 0in 0pt;line-height:normal;mso-background-themecolor:background2;mso-background-themeshade:230;mso-layout-grid-align:none;" class="MsoNormal"&gt;&lt;span style="font-size:10pt;mso-no-proof:yes;"&gt;&lt;/span&gt;&lt;span style="font-size:10pt;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span&gt;XPathNodeIterator&lt;/span&gt;
kids = patient.Select(NODE_NAME_PATIENT_ISOLATIONS, nsManagerMain);&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0in 0in 0pt;line-height:normal;mso-background-themecolor:background2;mso-background-themeshade:230;mso-layout-grid-align:none;" class="MsoNormal"&gt;&lt;span style="font-size:10pt;mso-no-proof:yes;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0in 0in 0pt;line-height:normal;mso-background-themecolor:background2;mso-background-themeshade:230;mso-layout-grid-align:none;" class="MsoNormal"&gt;&lt;span style="font-size:10pt;mso-no-proof:yes;"&gt;&lt;/span&gt;&lt;span style="font-size:10pt;mso-no-proof:yes;"&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span&gt;MessageBox&lt;/span&gt;.Show(&lt;span&gt;&amp;quot;Total Kids = &amp;quot;&lt;/span&gt; + kids.Count);&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0in 0in 0pt;line-height:normal;mso-background-themecolor:background2;mso-background-themeshade:230;mso-layout-grid-align:none;" class="MsoNormal"&gt;&lt;span style="font-size:10pt;mso-no-proof:yes;"&gt;&lt;/span&gt;&lt;span style="font-size:10pt;mso-no-proof:yes;"&gt;}&lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;

In this scenario I create a loop to apend 2 Isolation elements to an existing Patient.&amp;nbsp; When the loop starts the patient already has 1 isolation (from the template).&amp;nbsp; I would therefore expect 3 total isolations after the loop finished.&amp;nbsp; The first isolation added sets 2 attributes, one to the counter value and the other to an example value of 99.&amp;nbsp; After the first iteration the OuterXml for the patient looks as follows (notice only 1 Isolation):&lt;/font&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&amp;lt;d:Daily_Audit_Form_-_Patients xmlns:d=\&amp;quot;&lt;a href="http://schemas.microsoft.com/office/infopath/2003/ado/dataFields\"&gt;http://schemas.microsoft.com/office/infopath/2003/ado/dataFields\&lt;/a&gt;&amp;quot; &amp;gt;&lt;br /&gt;                  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;d:Daily_Audit_Form_-_Patient_Isolations Patient_ID=&amp;quot;99&amp;quot; Isolation_ID=&amp;quot;1&amp;quot;/&amp;gt;&lt;br /&gt;&amp;lt;/d:Daily_Audit_Form_-_Patients&amp;gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;The second iteration only sets the attribute with the counter value and does not use the example value of 99.&amp;nbsp; After the second iteration the OuterXml looks as follows:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&amp;lt;d:Daily_Audit_Form_-_Patients xmlns:d=\&amp;quot;&lt;a href="http://schemas.microsoft.com/office/infopath/2003/ado/dataFields\"&gt;http://schemas.microsoft.com/office/infopath/2003/ado/dataFields\&lt;/a&gt;&amp;quot; &amp;gt;&lt;br /&gt;                &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;d:Daily_Audit_Form_-_Patient_Isolations Patient_ID=&amp;quot;&amp;quot; Isolation_ID=&amp;quot;2&amp;quot;/&amp;gt;&lt;br /&gt;&amp;lt;/d:Daily_Audit_Form_-_Patients&amp;gt;&lt;br /&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;In this case, in addition to there only being 1 Isolation node, notice also that the example value of 99 is missing.&amp;nbsp; This tells me that the AppendChild() method is not a no-op and that in fact the new Isolation node is replacing the existing node, or, at the very least, is merely overcopying the original attributes.&lt;/p&gt;&lt;p&gt;The only thing I can suspect this point is that Isolations do have optional child elements but the schema defines the occurrences as being from 0 to unbounded.&amp;nbsp; And, there are also repeating tables bound to these children elements on the form but as this is not a GUI issue&amp;nbsp;I can&amp;#39;t fathom that that is material to what is happening...&lt;/p&gt;&lt;p&gt;So, any clues?&lt;/p&gt;&lt;p&gt;Thanks,&lt;br /&gt;Tony&lt;/p&gt;</description></item></channel></rss>