我在代码中创建了两个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节点,每个sub节点有多个item
发布于 2010-12-13 20:18:39
最终,我修复了这个bug,
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();
}
}
}https://stackoverflow.com/questions/4427930
复制相似问题