473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

response object assistance with returning xml.

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>
Nov 19 '05 #1
3 1220
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" %>

"Martin Dew" wrote:
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>

Nov 19 '05 #2
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

"Martin Dew" wrote:
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>

Nov 19 '05 #3
Hello Martin,

Make sure you do a Response.End() after the XML is written out. This stops
the processing of the current response.

--
Matt Berther
http://www.mattberther.com
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>


Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

35
by: Eitan | last post by:
Hello, How can I write a line (with carriage return + line feed) to the client ? response.write("abcd"), continue the last line, and doesn't put cr+lf. response.writeLn is illegal syntax... ...
6
by: Sam | last post by:
I have some issues with HTTP Headers and I was hoping for some pointers or references to good articles. Here is the problem. I have 6 .aspx pages, each page contains a common .ascx. This ascx...
0
by: iKiLL | last post by:
Hi All Code Below for this problem ERROR: "An existing connection was forcibly closed by the remote host"
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.