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/