asp:Xml control and Xml output


Grant Harmeyer

I am attempting to construct a simple ASP.NET Rss/Xml newsfeed. If anyone
has visited Don Box's Blog (, you will
notice that his Rss feed is exposed through an ASP.NET page. When you load
the .aspx page in IE, it displays just as an Xml doc would (colored nodes,
expandable node heirarchy, etc.).

I would like to mimic this using the <asp:Xml /> server control and pumping
the Xml to it from a CodeBehind XmlDocument(), but for now I am just
stuffing the Xml into the control manually for testing:

<asp:Xml runat="server">
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<title>Rss Feed</title>
<copyright>Copyright (c)</copyright>
<title>Empty Title</title>
<guid>Empty GUID</guid>
<link>Empty Link</link>
<pubDate>Empty Date</pubDate>
<description>Test Rss Xml Feed</description>
<body xmlns="">

When I try to load any Xml from the .aspx page, it just concatenates the
data in all nodes into one huge string, but viewing the source shows the Xml
just as I want it. This behavior even continues if all I do is load the
straight Xml into the .aspx page without the <asp:Xml /> server control. The
only conclusion I can come to is that this a mime-type issue, or I need an
XSLT stylesheet applyed to the Xml (but I am see that as the less likely

Never done much with Xml in ASP.NET, so sorry if this is elementary. TIA.

Grant Harmeyer

Chris Jackson

You need to set the ContentType property of the HttpResponse object to be of
type "text/xml" in order for the client to know what it is that you are
writing to it. Additionally, you don't need to wrap what you are writing
inside of a System.Web.UI.WebControls.Xml object, unless you need to
manipulate it. Whatever literal text you include in your aspx page will be
compiled as an object of type System.Web.UI.WebControls.Literal and fed
directly to the client, so you aren't gaining anything by doing that for
literal text.

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