How properly return XML from an ASPX page?

Discussion in 'ASP .Net' started by Ronald S. Cook, Mar 18, 2006.

  1. 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
     
    Ronald S. Cook, Mar 18, 2006
    #1
    1. Advertising

  2. 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

    --
    http://www.openmymind.net/



    "Ronald S. Cook" <> wrote in message
    news:...
    >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
    >
    >
    >
    >
     
    Karl Seguin [MVP], Mar 18, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sriram Mallajyosula

    How do I post data from aspx page to another aspx page.

    Sriram Mallajyosula, Nov 5, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    989
    Steve C. Orr [MVP, MCSD]
    Nov 5, 2003
  2. =?Utf-8?B?QmVu?=

    aspx page fails to display properly

    =?Utf-8?B?QmVu?=, Jan 22, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    389
    Steve C. Orr [MVP, MCSD]
    Jan 22, 2005
  3. John M
    Replies:
    1
    Views:
    1,176
    Kumar Reddi
    May 29, 2005
  4. Darrel
    Replies:
    1
    Views:
    1,833
    Alvin Bruney
    May 23, 2006
  5. webnet
    Replies:
    0
    Views:
    1,102
    webnet
    Nov 19, 2007
Loading...

Share This Page