By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,649 Members | 2,154 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,649 IT Pros & Developers. It's quick & easy.

Response.Write() rss xml

P: n/a
When writing rss xml to the client browser , is there any reason to load the
rss xml string into an XmlDocument and then Response.Write() the
XmlDocument.OuterXML.ToString() ?

option 1:

string rssXml = null;
-- build rssXML --
Response.Write(rssXml);

option 2:
string rssXml = null;
-- build rssXML --
XmlDocument xmlDoc = new XmlDocument;
xmlDoc.Load(rssXml);
Response.Write(xmlDoc.OuterXml.ToString());
May 4 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a


John A Grandy wrote:
When writing rss xml to the client browser , is there any reason to load the
rss xml string into an XmlDocument and then Response.Write() the
XmlDocument.OuterXML.ToString() ?

option 1:

string rssXml = null;
-- build rssXML --
Response.Write(rssXml);

option 2:
string rssXml = null;
-- build rssXML --
XmlDocument xmlDoc = new XmlDocument;
xmlDoc.Load(rssXml);
Response.Write(xmlDoc.OuterXml.ToString());

Why would you want to load into XmlDocument first to then Response.Write
the OuterXml?
I think what you want to do is use an XmlTextWriter to create and write
the XML to the HTTP response e.g.

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Xml" %>
<script runat="server">
void Page_Load () {
Response.ContentType = "application/xml";
XmlTextWriter xmlWriter = new XmlTextWriter(Response.Output);
xmlWriter.WriteStartDocument();
xmlWriter.WriteStartElement("gods");
xmlWriter.WriteElementString("god", "Kibo");
xmlWriter.WriteElementString("god", "Xibo");
xmlWriter.WriteEndDocument();
xmlWriter.Close();
}
</script>

Don't build the RSS/XML as a text string, instead make use of
XmlTextWriter which takes care of escaping characters and other
well-formedness constraints.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
May 5 '06 #2

P: n/a
Re:

Response.ContentType = "application/xml";
XmlTextWriter xmlWriter = new XmlTextWriter(Response.Output);
xmlWriter.Close();

How do you send the XMLTextWriter contents to the client browser ( assuming
you only want to send xml to the client browser ) ?

Don't you have to call XMLTextWriter.Flush() before you cal
XMLTextWriter.Close() ?

Or does the Page.Render() event handler still need to be overriden ?
Something like Response.Write(XMLTextWriter.{some method} )

"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:uh*************@TK2MSFTNGP02.phx.gbl...


John A Grandy wrote:
When writing rss xml to the client browser , is there any reason to load
the rss xml string into an XmlDocument and then Response.Write() the
XmlDocument.OuterXML.ToString() ?

option 1:

string rssXml = null;
-- build rssXML --
Response.Write(rssXml);

option 2:
string rssXml = null;
-- build rssXML --
XmlDocument xmlDoc = new XmlDocument;
xmlDoc.Load(rssXml);
Response.Write(xmlDoc.OuterXml.ToString());

Why would you want to load into XmlDocument first to then Response.Write
the OuterXml?
I think what you want to do is use an XmlTextWriter to create and write
the XML to the HTTP response e.g.

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Xml" %>
<script runat="server">
void Page_Load () {
Response.ContentType = "application/xml";
XmlTextWriter xmlWriter = new XmlTextWriter(Response.Output);
xmlWriter.WriteStartDocument();
xmlWriter.WriteStartElement("gods");
xmlWriter.WriteElementString("god", "Kibo");
xmlWriter.WriteElementString("god", "Xibo");
xmlWriter.WriteEndDocument();
xmlWriter.Close();
}
</script>

Don't build the RSS/XML as a text string, instead make use of
XmlTextWriter which takes care of escaping characters and other
well-formedness constraints.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

May 5 '06 #3

P: n/a


John A Grandy wrote:

Response.ContentType = "application/xml";
XmlTextWriter xmlWriter = new XmlTextWriter(Response.Output);
xmlWriter.Close();

How do you send the XMLTextWriter contents to the client browser


By creating the XmlTextWriter over Response.Output
new XmlTextWriter(Response.Output)


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
May 6 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.