I'm calling a web service via HttpWebResponse and then writing to a XML document with a Stream. When I view the XML file, I see every now and then some nodes that are broken with a line break such as, note the <Encode> tag is broken:

<Encode>
<EncodeFormat>300KB Flash V8 Progressive (320 x 180)</EncodeFormat>
<EncodeBitRateCode>312</EncodeBitRateCode>
<EncodeFormatCode>10</EncodeFormatCode>
</Encode>
<En
code>
<EncodeFormat>700KB Flash V7 Progressive (480 x 270)</EncodeFormat>
<EncodeBitRateCode>313</EncodeBitRateCode>
<EncodeFormatCode>10</EncodeFormatCode>
</Encode>
<Encode>

Below is how I'm doing the call. How can I ensure that the XML is written correctly??


//Declare new streamwriter object
StreamWriter sw;

//Create URI String
Uri myUri = new Uri(FeedPath);HttpWebRequest HttpWReq = (HttpWebRequest)WebRequest.Create(myUri);

//Set HttpWebRequest Specific Values
HttpWReq.KeepAlive = false;
HttpWReq.Timeout = Convert.ToInt32(ConfigurationManager.AppSettings["WebDelayedProcessingTimeout"]);
HttpWReq.ProtocolVersion = HttpVersion.Version10;
HttpWReq.ContentType = "text/xml";
HttpWReq.ContentLength = 0;
HttpWReq.Method = "POST";

//Set GOTO loop for retry attempts
callWebservice:

//Begin Pull
try{

//HttpWebRepsonse object
HttpWebResponse HttpWResp = (HttpWebResponse)HttpWReq.GetResponse();

//Call Webservice (with timeout included)
Stream streamResponse = HttpWResp.GetResponseStream();

//Assign result to stream reader
StreamReader streamRead = new StreamReader(streamResponse);

//Set Buffer read
int buffLength = 131072;
Char[] readBuff = new Char[buffLength];
int count = streamRead.Read(readBuff, 0, buffLength);

//Write results to XML file
while(count > 0)
{
//Read line
String outputData = new String(readBuff, 0, buffLength);

//Append line
sw = File.AppendText(Feed.FeedXMLFileName);

//Write Line
sw.WriteLine(outputData);

//Count reset
count = streamRead.Read(readBuff, 0, buffLength);

//Close Steam
sw.Close();
}

//Cleanup
HttpWResp.Close();
streamResponse.Close();
streamRead.Close();

}


Thanks
Jay