<?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>Iterate thru nodes and get value</title><link>https://www.infopathdev.com:443/forums/thread/72980.aspx</link><pubDate>Thu, 15 Dec 2011 15:51:25 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:72980</guid><dc:creator>jaxkookie</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/72980.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=72980</wfw:commentRss><description>&lt;p&gt;I posted the other day trying to find a solution to an issue. Now that I am a bit farther I have an issue I can seem to figure out. The requirements are to round trip data. I have a master section (non-repeating) and a child section (repeating table). I use the master to write or append values into the child. Eventually I may want to delete or edit an item. So using rules I write the value from the repeating table row into the Master fields. in the master I have an option to delete the item or update it. deleting is easy. updating was easy and on one test it worked. some reason going through my foreach loop, although the count is correct it seems to only return the value of the first child.&lt;/p&gt;&lt;pre&gt;&lt;code&gt;
 public void TestMe_Clicked(object sender, ClickedEventArgs e)
        {
            XPathNavigator root = MainDataSource.CreateNavigator();
            string xpathM = &amp;quot;/my:myFields/my:Master&amp;quot;;
            string xpathC = &amp;quot;/my:myFields/my:Chld/my:Child/my:Child&amp;quot;;

            XPathNavigator Master1 = root.SelectSingleNode(xpathM + &amp;quot;1&amp;quot;, NamespaceManager);
            XPathNavigator Master2 = root.SelectSingleNode(xpathM + &amp;quot;2&amp;quot;, NamespaceManager);
            XPathNavigator Master3 = root.SelectSingleNode(xpathM + &amp;quot;3&amp;quot;, NamespaceManager);
            XPathNavigator Master4 = root.SelectSingleNode(xpathM + &amp;quot;4&amp;quot;, NamespaceManager);
            XPathNavigator Master5 = root.SelectSingleNode(xpathM + &amp;quot;5&amp;quot;, NamespaceManager);
            XPathNavigator Master6 = root.SelectSingleNode(xpathM + &amp;quot;6&amp;quot;, NamespaceManager);
            XPathNavigator index = root.SelectSingleNode(&amp;quot;/my:myFields/my:index&amp;quot;, NamespaceManager);
            XPathNavigator Btn_lbl = root.SelectSingleNode(&amp;quot;/my:myFields/my:Btn_lbl&amp;quot;, NamespaceManager);
            XPathNavigator ChildrowNum = root.SelectSingleNode(&amp;quot;/my:myFields/my:ChildrowNum&amp;quot;, NamespaceManager);
            XPathNavigator Child1 = root.SelectSingleNode(xpathC + &amp;quot;1&amp;quot;, NamespaceManager);
            XPathNavigator Child2 = root.SelectSingleNode(xpathC + &amp;quot;2&amp;quot;, NamespaceManager);
            XPathNavigator Child3 = root.SelectSingleNode(xpathC + &amp;quot;3&amp;quot;, NamespaceManager);
            XPathNavigator Child4 = root.SelectSingleNode(xpathC + &amp;quot;4&amp;quot;, NamespaceManager);
            XPathNavigator Child5 = root.SelectSingleNode(xpathC + &amp;quot;5&amp;quot;, NamespaceManager);
            XPathNavigator Child6 = root.SelectSingleNode(xpathC + &amp;quot;6&amp;quot;, NamespaceManager);
            XPathNavigator rowNum = root.SelectSingleNode(&amp;quot;/my:myFields/my:Chld/my:Child/my:rowNum&amp;quot;, NamespaceManager);

            string xpathChld = &amp;quot;/my:myFields/my:Chld[1]&amp;quot;;
            string xpathrowNum1 = &amp;quot;//my:Child/my:rowNum[1]&amp;quot;;
            XPathNavigator nChld = MainDataSource.CreateNavigator().SelectSingleNode(xpathChld, NamespaceManager);
            XPathNodeIterator children = nChld.SelectChildren(XPathNodeType.Element);
            
            // Loop through collection and display information.
            if (Btn_lbl.Value.ToString().Contains(&amp;quot;Update&amp;quot;))
            {
                
                foreach (XPathNavigator selectedNode in children)
                {
                    XPathNavigator n2 = selectedNode.SelectSingleNode(xpathrowNum1, NamespaceManager);
                    if (n2.Value == ChildrowNum.Value)
                    {
                        Child1.SetValue(Master1.Value.ToString());
                        Child2.SetValue(Master2.Value.ToString());
                        Child3.SetValue(Master3.Value.ToString());
                        Child4.SetValue(Master4.Value.ToString());
                        Child5.SetValue(Master5.Value.ToString());
                        Child6.SetValue(Master6.Value.ToString());
                    }
                }


                //XPathNodeIterator rows = root.Select(xpathChld, NamespaceManager);

                //while (rows.MoveNext())
                //{
                //    string field1 = rows.Current.SelectSingleNode(
                //    &amp;quot;my:rowNum&amp;quot;, NamespaceManager).Value;
                //     if (field1 == ChildrowNum.Value)
                //     {
                //         Child1.SetValue(Master1.Value.ToString());
                //         Child2.SetValue(Master2.Value.ToString());
                //         Child3.SetValue(Master3.Value.ToString());
                //         Child4.SetValue(Master4.Value.ToString());
                //         Child5.SetValue(Master5.Value.ToString());
                //         Child6.SetValue(Master6.Value.ToString());
                //         break;
                //     }
                     
                //} 

            }


           

            else
            {


                XPathNavigator lastrow = root.SelectSingleNode(&amp;quot;//my:Child[last()]&amp;quot;, NamespaceManager);
                string lstrw = lastrow.SelectSingleNode(&amp;quot;my:rowNum&amp;quot;, NamespaceManager).Value.ToString();
               

                XPathNavigator C1 = root.SelectSingleNode(&amp;quot;/my:myFields/my:Chld/my:Child/my:Child1&amp;quot;, NamespaceManager);
                XPathNavigator C1Parent = root.SelectSingleNode(&amp;quot;/my:myFields/my:Chld/my:Child[1]&amp;quot;, NamespaceManager);

                int i = 1;
                i = Convert.ToInt32(lstrw) + 1;

                if (C1.Value == &amp;quot;0&amp;quot;)
                {
                    if (C1Parent != null)
                    {
                       

                        Child1.SetValue(Master1.Value.ToString());
                        Child2.SetValue(Master2.Value.ToString());
                        Child3.SetValue(Master3.Value.ToString());
                        Child4.SetValue(Master4.Value.ToString());
                        Child5.SetValue(Master5.Value.ToString());
                        Child6.SetValue(Master6.Value.ToString());
                        rowNum.SetValue(i.ToString());

                    }

                }
                else
                {
                    XPathNavigator navigator = MainDataSource.CreateNavigator();
                    navigator.MoveToFollowing(XPathNodeType.Element);

                    XPathNavigator sectionNode = navigator.SelectSingleNode(&amp;quot;/my:myFields/my:Chld&amp;quot;, NamespaceManager);

                    string ns = sectionNode.NamespaceURI;

                    XmlWriter writer = sectionNode.AppendChild();

                    writer.WriteStartElement(&amp;quot;my&amp;quot;, &amp;quot;Child&amp;quot;, ns);
                    writer.WriteElementString(&amp;quot;my&amp;quot;, &amp;quot;Child1&amp;quot;, ns, Master1.Value.ToString());
                    writer.WriteElementString(&amp;quot;my&amp;quot;, &amp;quot;Child2&amp;quot;, ns, Master2.Value.ToString());
                    writer.WriteElementString(&amp;quot;my&amp;quot;, &amp;quot;Child3&amp;quot;, ns, Master3.Value.ToString());
                    writer.WriteElementString(&amp;quot;my&amp;quot;, &amp;quot;Child4&amp;quot;, ns, Master4.Value.ToString());
                    writer.WriteElementString(&amp;quot;my&amp;quot;, &amp;quot;Child5&amp;quot;, ns, Master5.Value.ToString());
                    writer.WriteElementString(&amp;quot;my&amp;quot;, &amp;quot;Child6&amp;quot;, ns, Master6.Value.ToString());
                    writer.WriteElementString(&amp;quot;my&amp;quot;, &amp;quot;rowNum&amp;quot;, ns, i.ToString());

                    writer.WriteEndElement();

                    writer.Close();
                }


            }

            index.SetValue(&amp;quot;1&amp;quot;);
           
        }&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;Field layout&lt;/p&gt;&lt;pre&gt;myFields
   Master1
   Master2
   ...
   Chld
      Child
         Child1
         Child2
         ...

few other fields

&lt;/pre&gt;
&lt;p&gt;Maybe it is my lack of understand of XPATH, but n2 seems to only be returning 1 as a value. as each row is inserted the next number is assigned. When it writes the value to the master the rowNum maatches ChildrowNum, but in the foeach loop it is only 1. in the while loop commented out it matches, but none of the fields are updated. Can any one point out what I am missing?&lt;/p&gt;</description></item></channel></rss>