I'm connecting to an API, or service like that, which returns me an xml when it finds data in the database, but unfortunately it returns a string if nothing is found or an error occurs. In my application I'm using the following code to connect to this API and retrieve the data:
WebRequest request = WebRequest.Create(_fileUrl);
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
Stream dataStream = response.GetResponseStream();
var reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
xmlDoc.LoadXml(responseFromServer);
As you might expect when there is no data in the database, an error occurs when giving a load in xmlDoc because the responseFromServer variable is not XML but a string.
The question is: How do I identify whether my string returned an xml or not? I do not want to "" try to give a load and if it does not work I understand that what came up was a string. I may be masking other errors when doing this.