Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用XPATH解析元素的所有子元素_C#_Xpath - Fatal编程技术网

C# 如何使用XPATH解析元素的所有子元素

C# 如何使用XPATH解析元素的所有子元素,c#,xpath,C#,Xpath,我正在用XPATH解析xml文件 nodes = navigator.Select("/bk:ChaosPlan/bk:SubscriptionInfo",manager); while (nodes.MoveNext()) { XPathNavigator childNodes = nodes.Current.Clone(); childNodes.MoveToFirstAttribute(); strin

我正在用XPATH解析xml文件

nodes = navigator.Select("/bk:ChaosPlan/bk:SubscriptionInfo",manager);
while (nodes.MoveNext())
        {
            XPathNavigator childNodes = nodes.Current.Clone();
            childNodes.MoveToFirstAttribute();
            string name = childNodes.Value;
            bool x = true;
            x= childNodes.MoveToFirstChild();
            string Id = childNodes.Value;
            subNamenAndId.Add(new Result(name, Id));
            childNodes.MoveToNext();
            certName = childNodes.Value;
            childNodes.MoveToNext();
            templateName = childNodes.Value;
}

但当我移动到第一个孩子时(在boolx=true;line之后),它返回false,而不是移动到第一个孩子


我需要做的是,在运行查询后获取第一个元素的属性,然后遍历该元素的前3个子元素并存储这些值。

当您的XPathNavigator位于属性调用上时,首先能够移动到子节点。

您能展示一个发生这种情况的示例Xml文档吗?