Hi,
I need some help.
I am retrieving a result set from the database & storing it in into a Datatable using C#. I am then using the WriteXML method of the Datatable to convert it into XML string & then I am writing the XML string to the page after setting the content type of the page to "text/xml". When I run my page for the first time I get the error
The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
------------------------------------------------------------
Only one top level element is allowed in an XML document.
When I refresh the page this error goes away & it shows me the correct XML string.
Following is the code that I am using after getting the result in the Datatable:
string strRateXML = "";
System.IO.StringWriter sw = new System.IO.StringWriter();
DataTable dtCurrent = clsBTSql.GetDataTable();
dtCurrent.TableName = "Rates";
dtCurrent.WriteXml(sw);
strRateXML = sw.ToString();
Response.Clear();
Response.ContentType = "text/xml";
Response.Write("<?xml version='1.0' encoding='ISO-8859-1'?>");
Response.Write(strRateXML);
Response.Flush();
Response.End();
Can anybody please tell me what am I doing wrong here?
I need some help.
I am retrieving a result set from the database & storing it in into a Datatable using C#. I am then using the WriteXML method of the Datatable to convert it into XML string & then I am writing the XML string to the page after setting the content type of the page to "text/xml". When I run my page for the first time I get the error
The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
------------------------------------------------------------
Only one top level element is allowed in an XML document.
When I refresh the page this error goes away & it shows me the correct XML string.
Following is the code that I am using after getting the result in the Datatable:
string strRateXML = "";
System.IO.StringWriter sw = new System.IO.StringWriter();
DataTable dtCurrent = clsBTSql.GetDataTable();
dtCurrent.TableName = "Rates";
dtCurrent.WriteXml(sw);
strRateXML = sw.ToString();
Response.Clear();
Response.ContentType = "text/xml";
Response.Write("<?xml version='1.0' encoding='ISO-8859-1'?>");
Response.Write(strRateXML);
Response.Flush();
Response.End();
Can anybody please tell me what am I doing wrong here?