weirdness with xPathNodeIterator - InfoPath Dev
in

InfoPath Dev

weirdness with xPathNodeIterator

Last post 04-30-2007 10:05 AM by erinselena. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 04-30-2007 08:14 AM

    weirdness with xPathNodeIterator

    Hello ALl,

    Somthing weird is happening and i can't seem to see why. I have an XpathNodeIterator and it gives me back 2 nodes but continuously loops and won't stop. It should only loop twice but it's stuck in an infinite loop. anyone know why this might be happening? Here is the code.

     

    for ( int i = 0; i < cloneD.NumberClones; i++ )
                                {
                                    //create the new cloned row
                                    string newIdNumber = Guid.NewGuid( ).ToString( );
                                    XPathNavigator newRow = formControl1.XmlForm.MainDataSource.CreateNavigator( ).SelectSingleNode( Constants.ASSET_INSTANCE_ID + "[text()='" + identifier + "'" + "]", xmlnsm );
                                    newRow.MoveToParent( );
                                    newRow.InsertAfter( newRow.OuterXml );
                                    newRow.SelectSingleNode( "./my:ass_InstanceID", xmlnsm ).SetValue( newIdNumber );

                                    //create the new attachment row if there are any attachments
                                    XPathNodeIterator attIterator = formControl1.XmlForm.MainDataSource.CreateNavigator( ).Select( Constants.ATTACHMENT_ASSET_INSTANCE + "[text()='" + identifier + "'" + "]", xmlnsm );
                                    while ( attIterator.MoveNext( ) )  <== this is where the infinite loop is occurring
                                    {
                                        attIterator.Current.MoveToParent( );
                                        attIterator.Current.InsertAfter( attIterator.Current.OuterXml );
                                        attIterator.Current.SelectSingleNode( Constants.ATTACHMENT_SURVEY_ITEM, xmlnsm ).SetValue( newIdNumber );
                                    }
                                }

  • 04-30-2007 08:21 AM In reply to

    Re: weirdness with xPathNodeIterator

    OK i think i get why.. it has something to do with me inserting a new node while looping with the xpathnodeiterator. I think it's screwing up the iterator. Instead i am going to try using a for loop.
  • 04-30-2007 08:59 AM In reply to

    Re: weirdness with xPathNodeIterator

    ok so what i've tried to do is loop through the iterator and put each node into a list. then i loop through the list and copy each node into the main datasource BUT there is a problem with putting each node in the list during the iterator execution. It keeps overwritting all of the entries to be the current node so if there are 3 different nodes in the iterator all 3 of them are the same node instance.. this doesn't make sense/. anyone know why this is happening?

    thanks,

    erin

  • 04-30-2007 10:05 AM In reply to

    Re: weirdness with xPathNodeIterator

    ok so i've fixed this.. what i had to do was store a CLONE of the node in the list and that solved my problem
Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.