【问题标题】:Test is a node exists in the XML FILE [duplicate]测试是否存在于 XML 文件中的节点 [重复]
【发布时间】:2020-08-21 08:42:20
【问题描述】:

如果节点存在于 XML 文件中,我如何在 C# 中进行测试?

我像这样阅读我的 xml 文件:

 XmlDocument docxml = new XmlDocument();
 docxml.LoadXml("test.xml");
 XmlNode root = docxml.DocumentElement;

我想测试我的文件中是否存在特定节点。

我该怎么做?

【问题讨论】:

标签: c# xml


【解决方案1】:
   XmlDocument tourdetailsxml = new XmlDocument();
                XmlReader xmlReader = XmlReader.Create("test.xml");
                tourdetailsxml.Load(xmlReader);
                var xdoc = XDocument.Parse(tourdetailsxml.InnerXml);
                var Error = xdoc.Descendants("Error").ToList();
                for(var i = 0; i < Error.Count(); i++){

                }

【讨论】:

  • 使用 XPath 更简单快捷
猜你喜欢
  • 1970-01-01
  • 2011-04-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-02
  • 1970-01-01
相关资源
最近更新 更多