Mahek
Mahek

Reputation: 562

How to retrieve particular data from xml file using c#

As a part of functional testing of my Api, I want to scrap the "body" part of given xml using C#. How can I do that?

This is my xml file

<Root>
  <collection>  </collection>
  <run>
      <stats>  </stats>
      <execution>
         <cursor>   </cursor>
         <response>
             <body> Some Values here </body>
         </response>
      </execution>
  </run>
</Root>

Upvotes: 0

Views: 160

Answers (1)

Uday
Uday

Reputation: 1560

First Load the Your xml in XmlDocument object and than using GetElementsByTagName("body") you can get the Node say 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 contains you body text that is

Some Values here

Upvotes: 1

Related Questions