如何使用c#从xml文件中检索特定的数据
本文关键字:检索 数据 文件 何使用 xml | 更新日期: 2023-09-27 18:11:37
作为Api功能测试的一部分,我想使用c#废弃给定xml的"body"部分。我该怎么做呢?
这是我的xml文件
<Root>
<collection> </collection>
<run>
<stats> </stats>
<execution>
<cursor> </cursor>
<response>
<body> Some Values here </body>
</response>
</execution>
</run>
</Root>
首先在XmlDocument对象中加载您的xml,然后使用GetElementsByTagName("body")
,您可以获得节点说体
XmlDocument _LocalInfo_Xml = new XmlDocument();
_LocalInfo_Xml.Load(_LocalInfo_Path);
XmlElement _XmlElement;
_XmlElement = _LocalInfo_Xml.GetElementsByTagName("body")[0] as XmlElement;
string Value = _XmlElement.InnerText;
Now Value包含正文文本
这里的一些值