Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1079063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:48:51+00:00 2026-05-16T21:48:51+00:00

Looked at a tutorial but couldn’t get this working: default.aspx: <%@ Page Language=C# ContentType=text/xml

  • 0

Looked at a tutorial but couldn’t get this working:

default.aspx:

<%@ Page Language="C#" ContentType="text/xml" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="rssPubba.Default" %>

default.aspx.cs

 protected void Page_Load(object sender, EventArgs e)
    {
        Response.ContentType = "text/xml";
        Response.ContentEncoding = Encoding.UTF8;

        XmlDocument doc = new XmlDocument();

        // XML declaration
        XmlNode declaration = doc.CreateNode(XmlNodeType.XmlDeclaration, null, null);
        doc.AppendChild(declaration);

        // Root element: article
        XmlElement root = doc.CreateElement("article");
        doc.AppendChild(root);

        // Sub-element: author
        XmlElement author = doc.CreateElement("author");
        author.InnerText = "Faisal Khan";
        root.AppendChild(author);

        // Attribute: isadmin
        XmlAttribute isadmin = doc.CreateAttribute("isadmin");
        isadmin.Value = "true";
        author.Attributes.Append(isadmin);

        // Sub-element: title
        XmlElement title = doc.CreateElement("title");
        title.InnerText = "Sample XML Document";
        root.AppendChild(title);

        // Sub-element: body (CDATA)
        XmlElement body = doc.CreateElement("body");
        XmlNode cdata = doc.CreateCDataSection("This is the body of the article.");
        body.AppendChild(cdata);
        root.AppendChild(body);

        doc.Save(Response.OutputStream);
    }

however when I try to display it the browser seem to interpreting it as markup:

output:

<article> 
  <author isadmin="true">Faisal Khan</author> 
  <title>Sample XML Document</title> 
  <body><![CDATA[This is the body of the article.]]></body> 
</article>

What changes to I have to make?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T21:48:51+00:00Added an answer on May 16, 2026 at 9:48 pm

    I suspect it’s clearing the output so far and writing the normal page data. Two options:

    • Use an ashx instead of aspx to create a handler, so that it knows you’re not trying to render the page. That’s probably the most sensible approach, if it’s always meant to be generating an XML document.
    • Complete the request when you’ve written the data, e.g. by calling Response.CompleteRequest()

    (I’d also recommend using LINQ to XML as a rather nicer API for constructing XML documents than the old DOM API, but it’s up to you 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got zero experience with Python. I have looked around some tutorial materials, but
This is driving me nuts. I've looked at all the relevant MSDN tutorials but
I looked around but haven't found an answer to this. I have a CentOS
I have looked everywhere but couldn't find it anywhere. I installed it successfully but
This is no doubt a very simple question, but unfortunately I have looked around
I have looked so long for nice tutorials, but still couldn't find any for
I looked for this on the web, but I could not find any clear
I followed the tutorial exactly: http://github.com/binarylogic/authlogic_example But I am wondering how can I get
I have read the boost asio reference, gone through the tutorial and looked at
I looked at django-celery tutorial and I think it will really help me running

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.