xml response removing elements

132 views Asked by At

I am working on a .Net project where I need to take the xml response and put it as a comment on the html page.
Below is the code I am using to receive a response in from a url.

WebRequest request = HttpWebRequest.Create(url);

using (WebResponse response = request.GetResponse())
{
   Stream responseStream = response.GetResponseStream();

   if (responseStream != null)
   {
      using (var reader = new StreamReader(responseStream))
      {
         xmlResponse = reader.ReadToEnd();
      }
   }
}
return xmlResponse;

I do receive the response but some of the nodes are missing. For eg: The response when I hit the url directly looks like below:

<ROOT xmlns:i="ABC" xmlns="ABC">
<RESERVATIONLIST>
<RESERVATION>
<BOOKINGSTATUS>Confirmed</BOOKINGSTATUS>    
<ITEMAMOUNTLIST>
<ITEMAMOUNT>
<PASSENGER>Able K, Tester J, Able S</PASSENGER>
<QTY>3</QTY>
</ITEMAMOUNT>
<ITEMAMOUNT>
<PASSENGER>Able K, Tester J</PASSENGER>
<PLUSMINUS>+</PLUSMINUS>
<QTY>2</QTY>
</ITEMAMOUNT>
<ITEMAMOUNT>
</RESERVATION>
</RESERVATIONLIST>
</RESCARD>

But instead when I receive, I see the following:

<RESERVATIONLIST>
<BOOKINGSTATUS>Confirmed</BOOKINGSTATUS>
<ITEMAMOUNTLIST>
    <PASSENGER>Able K, Tester J, Able S</PASSENGER>
    <QTY>3</QTY>
</ITEMAMOUNTLIST>
<ITEMAMOUNTLIST>
    <PASSENGER>Able K, Tester J</PASSENGER>
    <QTY>2</QTY>
</ITEMAMOUNTLIST>
</RESERVATIONLIST>

I looked at a lot of posts, for receiving the XML document directly but all of them were throwing the same error of Data invalid at Root Level. And using this method I am not receiving the exact response. Can anyone help me in this? Thanks.

0

There are 0 answers