如果使用C#找到元素,如何测试XML文档 [英] How to test an XML document if an element is found using C#

查看:59
本文介绍了如果使用C#找到元素,如何测试XML文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在阅读XML文档,我想检查是否在该xml文档中找到了一个名为PrescribedRegimenTypeCode的特定元素,如果它找到了元素然后得到它的价值,我试过以下



我尝试过:



Hello guys,

I am reading an XML Document and i want to check if a particular Element called PrescribedRegimenTypeCode is found in that xml Document if it find the Element then get it Value, i have tried the following

What I have tried:

XDocument xd = XDocument.Load(@"D:\ConsoleApplication4\MyData.xml");  
  
string result2 = "";  
result2  = xd.Element("Container").Element("IndividualReport").Element("Condition").Element("Regimen").Element("PrescribedRegimenTypeCode").Value;  





我将不胜感激任何建议



I will appreciate any suggestions

推荐答案

参见如何在C#中获取XML元素的值? / a> [ ^ ]。


这篇关于如果使用C#找到元素,如何测试XML文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆