response object assistance with returning xml.

M

Martin Dew

I have a page which upon opening gets information from a database, the field
it returns has structured xml stored in it.

private void Page_Load(object sender, System.EventArgs e)

{

if (!IsPostBack) {

GetRecordFromServer(this.Request.QueryString[0].ToString());

}

}

private void GetRecordFromServer(string searchID) {


DataSet ds = dbAuditLog.GetEntry(new Guid(searchID));

DataTable dt = ds.Tables[0];


Response.ContentType = "Text/XML";

Response.Output.Write(dt.Rows[0]["XMLText"].ToString());


}



The problem I am having is that the resulting page does not quite display
properly, it always seems to add the following to the end of the xml, I just
want the xml from my field to be streamed to the response, and that is all,
can anyone help ?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>dbaudmess</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form name="Form1" method="post"
action="dbaudmess.aspx?searchID=551687bf-07db-4199-8be6-2a2682d6e49f"
id="Form1">
<input type="hidden" name="__VIEWSTATE"
value="dDwtNjU0MzcyMTk1Ozs+/NB5NnLZUiFzN88M2i+3c1vA1l0=" />

</form>
</body>
</HTML>
 
G

Guest

You need to rip everything (well almost everything) out of your aspx file;

For example;

<%@ Page language="c#" Codebehind="DisplayXML.aspx.cs"
AutoEventWireup="false" Inherits="YourNamespace.DisplayXML" %>
 
G

Guest

I also have an application that returns Xml to the user. I actually use
"text/plain" as the content type, but that's because the user will likely
need to copy and paste the Xml and if I use "text/xml" then IE hides the Xml
tags and only displays the text.

But anyway, try this before you write to the stream:

HttpContext context = HttpContext.Current;
context.Response.Clear();
context.Response.ContentType = "text/xml";

Or more simply :
Response.Clear();
Response.ContentType = "text/xml";

The first is what I have in my code and both snippets should be the same,
but it's just what I wrote at the time, I don't remember why I chose that
method.

Regards,
Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top