0

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>
2
  • You can use XPath or maybe try to deserailize this data into .net objects. XPath link - msdn.microsoft.com/en-us/library/d271ytdx(v=vs.110).aspx. Commented Oct 5, 2016 at 4:07
  • What does scrap the body mean? Delete it? Bad data in the value? What? Commented Oct 5, 2016 at 11:26

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.