移动XPathNodeIterator和Child XPathNodeIterator时的同步问题

时间:2010-12-13 10:35:46

标签: c# c#-2.0 xpathnodeiterator

我在代码中创建了两个XPathNodeIterator itchildIt

此代码段,

string selectSfStr = "Equipment/Main/Sub";
            it = nav.Select(selectSfStr);

            while (it.MoveNext())
            {                
                ; // do something here

                if (it.Current.HasChildren)
                {


                    XPathNodeIterator childIt;
                    string selectChildSfStr = "//item";
                    childIt = nav.Select(selectChildSfStr);

                    while (childIt.MoveNext())
                    {
                           ; // do something here, but I found bug. The childIt can't move sychronized with the parent `it`.
                           ;// How can I synchronize `childIt` here when I moved to next `it`.
                    }
                 }
         }

我的xml文件嵌套了Equipment/Main/Sub/item序列,每个sub个节点都有多个item个节点和多个sub

1 个答案:

答案 0 :(得分:0)

最终,我修复了这个错误,

while (it.MoveNext())
            {                
                // do something here


                if (it.Current.HasChildren)
                {


                    XPathNodeIterator childIt;
                    childIt = null;                    
                    childIt = it.Current.SelectChildren("item", ""); 

                    while (childIt.MoveNext())
                    {
                       // do something here

                       childIt.Current.MoveToParent();
                    }
                }
          }