Groups | Blog | Home
all groups > dotnet xml > may 2006 >

dotnet xml : Response.Write() rss xml


John A Grandy
5/4/2006 2:21:40 PM
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());

John A Grandy
5/5/2006 11:18:23 AM
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} )



[quoted text, click to view]

Martin Honnen
5/5/2006 3:11:49 PM


[quoted text, click to view]


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
Martin Honnen
5/6/2006 1:17:47 PM


[quoted text, click to view]


[quoted text, click to view]

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




--

Martin Honnen --- MVP XML
AddThis Social Bookmark Button