Response.Write() rss xml

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John A Grandy

    Response.Write() rss xml

    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.Out erXML.ToString( ) ?

    option 1:

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

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


  • Martin Honnen

    #2
    Re: Response.Write( ) rss xml



    John A Grandy wrote:
    [color=blue]
    > 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.Out erXML.ToString( ) ?
    >
    > option 1:
    >
    > string rssXml = null;
    > -- build rssXML --
    > Response.Write( rssXml);
    >
    > option 2:
    > string rssXml = null;
    > -- build rssXML --
    > XmlDocument xmlDoc = new XmlDocument;
    > xmlDoc.Load(rss Xml);
    > Response.Write( xmlDoc.OuterXml .ToString());[/color]


    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="Syst em.Xml" %>
    <script runat="server">
    void Page_Load () {
    Response.Conten tType = "applicatio n/xml";
    XmlTextWriter xmlWriter = new XmlTextWriter(R esponse.Output) ;
    xmlWriter.Write StartDocument() ;
    xmlWriter.Write StartElement("g ods");
    xmlWriter.Write ElementString(" god", "Kibo");
    xmlWriter.Write ElementString(" god", "Xibo");
    xmlWriter.Write EndDocument();
    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

    Comment

    • John A Grandy

      #3
      Re: Response.Write( ) rss xml

      Re:

      Response.Conten tType = "applicatio n/xml";
      XmlTextWriter xmlWriter = new XmlTextWriter(R esponse.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.F lush() before you cal
      XMLTextWriter.C lose() ?

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



      "Martin Honnen" <mahotrash@yaho o.de> wrote in message
      news:uhr15VEcGH A.536@TK2MSFTNG P02.phx.gbl...[color=blue]
      >
      >
      > John A Grandy wrote:
      >[color=green]
      >> 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.Out erXML.ToString( ) ?
      >>
      >> option 1:
      >>
      >> string rssXml = null;
      >> -- build rssXML --
      >> Response.Write( rssXml);
      >>
      >> option 2:
      >> string rssXml = null;
      >> -- build rssXML --
      >> XmlDocument xmlDoc = new XmlDocument;
      >> xmlDoc.Load(rss Xml);
      >> Response.Write( xmlDoc.OuterXml .ToString());[/color]
      >
      >
      > 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="Syst em.Xml" %>
      > <script runat="server">
      > void Page_Load () {
      > Response.Conten tType = "applicatio n/xml";
      > XmlTextWriter xmlWriter = new XmlTextWriter(R esponse.Output) ;
      > xmlWriter.Write StartDocument() ;
      > xmlWriter.Write StartElement("g ods");
      > xmlWriter.Write ElementString(" god", "Kibo");
      > xmlWriter.Write ElementString(" god", "Xibo");
      > xmlWriter.Write EndDocument();
      > 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/[/color]


      Comment

      • Martin Honnen

        #4
        Re: Response.Write( ) rss xml



        John A Grandy wrote:

        [color=blue]
        > Response.Conten tType = "applicatio n/xml";
        > XmlTextWriter xmlWriter = new XmlTextWriter(R esponse.Output) ;
        > xmlWriter.Close ();
        >
        > How do you send the XMLTextWriter contents to the client browser[/color]

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




        --

        Martin Honnen --- MVP XML

        Comment

        Working...