我在代码中创建了两个XPathNodeIterator it
和childIt
此代码段,
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
答案 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();
}
}
}