移动XPathNodeIterator和Child XPathNodeIterator的同步问题

发布于 2024-10-07 11:33:14 字数 1006 浏览 4 评论 0原文

我在代码中创建了两个 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节点有多个sub节点和多个item

I created two XPathNodeIterator it and childIt in my code

Code snippet as this,

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`.
                    }
                 }
         }

my xml file nested with the sequence of Equipment/Main/Sub/item and there are multi sub nodes and multi item for each of sub nodes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

羁拥 2024-10-14 11:33:14

最终,我修复了这个错误,如下所示:

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();
                    }
                }
          }

Eventually, I fixed this bug as this,

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();
                    }
                }
          }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文