0

我创建了两个 XPathNodeIteratoritchildIt在我的代码中

像这样的代码片段,

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节点和多个itemsub

4

1 回答 1

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();
                    }
                }
          }
于 2010-12-13T12:18:38.643 回答