asp:Xml control and Xml output


G

Grant Harmeyer

I am attempting to construct a simple ASP.NET Rss/Xml newsfeed. If anyone
has visited Don Box's Blog (http://www.gotdotnet.com/team/dbox/), 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">
<channel>
<title>Rss Feed</title>
<link>http://localhost/rss/</link>
<copyright>Copyright (c)</copyright>
<item>
<title>Empty Title</title>
<guid>Empty GUID</guid>
<link>Empty Link</link>
<pubDate>Empty Date</pubDate>
<description>Test Rss Xml Feed</description>
<body xmlns="http://www.w3.org/1999/xhtml">
Test
</body>
</item>
</channel>
</rss>
</asp:Xml>

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
issue).

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


Grant Harmeyer
 
Ad

Advertisements

C

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

Top