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 8391737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:20:29+00:00 2026-06-09T19:20:29+00:00

I’m writing a page that needs to exchange some information with a SQL server.

  • 0

I’m writing a page that needs to exchange some information with a SQL server. For portability reasons, and because I hate writing ASP but I’ve been told to do this on the IIS 7 server, I’m writing the page in pure HTML, a generic handler (ASHX) in C# .NET to do the server-side stuff, and using AJAX to communicate between them. I’ve got this approach working using Response.ContentType = "text/plain";, but I’d like to return several pieces of information with one request, so I’m switching to XML or JSON, leaning toward XML.

So, to return XML, I change to "text/xml", but then do I just Response.Write the whole XML code verbatim, or is there a more succinct way built into .NET? Same question for JSON. I know there are specific methods in jQuery (even just JavaScript) for parsing the returned data, so I was wondering if there was something similar in .NET to encode.

  • 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-06-09T19:20:31+00:00Added an answer on June 9, 2026 at 7:20 pm

    but then do I just Response.Write the whole XML code verbatim, or is
    there a more succinct way built into .NET?

    You could use a XmlWriter, XDocument or even a XmlSerializer to build the XML and then write it to the Response.OutputStream.

    Here’s an example with a XDocument:

    public void ProcessRequest(HttpContext context)
    {
        var doc = new XDocument(
            new XElement(
                "messages",
                new XElement(
                    "message", 
                    new XAttribute("id", "1"), 
                    new XAttribute("value", "message 1"), 
                ),
                new XElement(
                    "message", 
                    new XAttribute("id", "2"), 
                    new XAttribute("value", "message 2")
                )
            )
        );
        context.Response.ContentType = "text/xml";
        using (var writer = XmlWriter.Create(context.Response.OutputStream))
        {
            doc.WriteTo(writer);
        }
    }
    

    Same question for JSON

    You would use a Json serializer such as JavaScriptSerializer and then write it to the output stream:

    public void ProcessRequest(HttpContext context)
    {
        var serializer = new JavaScriptSerializer();
        string json = serializer.Serialize(new
        {
            messages = new[]
            {
                new { id = 1, value = "message 1" },
                new { id = 2, value = "message 2" },
            }
        });
        context.Response.ContentType = "application/json";
        context.Response.Write(json);
    }
    

    This being said, you should be aware that ASP.NET MVC or the knocking on the door Web API are now the preferred ways to expose such data instead of writing generic handlers.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into

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.