How properly return XML from an ASPX page?

R

Ronald S. Cook

I have an ASPX page that returns XML to the calling client. While the code
below works, I don't think it's proper because it's not encoded as XML.
I.e. special characters might screw things up.



Can anyone please tell me the more proper way to do this?



<%@ Page Language="C#" %>



<html>

<body>

<%

Response.Write("<?xml version='1.0'?>");

Response.Write("<Westin><Event><Name>RECEPTION</Name><Floor>2nd
Floor</Floor><StartTime>8:00 AM</StartTime><EndTime>10:00
AM</EndTime></Event></Westin>");

%>



</body>

</html>



Thanks,

Ron
 
K

Karl Seguin [MVP]

Well, you should probably remove the <html> and <body> and ideally hook
into the onLoad event.. your page should be empty

void override onLoad(...)
{
Response.Clear();
Response.ContentType = "text/xml";
Response.Write(UR XML HERE)
Response.End();
}


karl
 

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,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top