c# - 如何使用 XPathDocument 和 C# 获取节点数?

标签 c# asp.net

我有一个简单的 xml 文档,我想获取某个节点的计数。我怎样才能做到这一点?现在我正在使用以下语法来获取节点。

  // send request and strore in xpath doc (read-only)
    XPathDocument xDoc = new XPathDocument(requestURL);

    // Create navigator  
    XPathNavigator navigator = xDoc.CreateNavigator();

    XPathNavigator navError = navigator.SelectSingleNode("/api/error");

最佳答案

要统计api/error的实例数吗?如果是这样尝试:

int errorCount = navigator.Select("/api/error").Count;

关于c# - 如何使用 XPathDocument 和 C# 获取节点数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5279326/

相关文章:

c# - 使用 Kinect 进行人脸检测

c# - 类方法中的随机数生成器

asp.net - 覆盖 Azure 应用程序设置中的 appsettings.json 值

c# - 如何使用 Web.config 转换更改 appSettings 部分中的属性值

c# - wb.DownloadFileAsync 抛出 "WebClient does not support concurrent I/O operations."异常

c# - 我应该拆分我的 edmx 吗?

c# - 以各种格式呈现时解析日期的推荐方法

asp.net - 如何在不获取 "????"的情况下将希伯来字符编码到数据库

asp.net - GridView - 在空数据源上显示标题

c# - Asp.Net:动态切换 UserControl - 如何?