Display XML file

Discussion in 'ASP .Net' started by shapper, Oct 15, 2006.

  1. shapper

    shapper Guest

    Hello,

    I am using a XSL file to transform a XML file.
    Then I want to display the XML file in browser as XML type.
    I am working on an Asp.Net 2.0 HTTP Generic Handler (.ashx).

    My code is:

    Public Sub ProcessRequest(ByVal context As HttpContext) Implements
    IHttpHandler.ProcessRequest

    Dim server As System.Web.HttpServerUtility =
    System.Web.HttpContext.Current.Server
    Dim docXml As XmlDocument = New XmlDocument
    docXml.Load(server.MapPath("~/App_Data/Doc.Xml"))
    Dim docXsl As XslCompiledTransform = New XslCompiledTransform
    docXsl.Load(server.MapPath("~/App_Data/Doc.xsl"))
    docXsl.Transform(docXml, Nothing,
    HttpContext.Current.Response.Output)


    ' context.Response.ContentType = "text/xml"
    ' ??? context.Response.Write(...)

    End Sub

    I need to display the XML file in my browser as XML file.
    With docXsl.Transform(docXml, Nothing,
    HttpContext.Current.Response.Output) I am not doing it.

    Is there an option to make this hapening?

    Maybe if I save the result in a XML object and then place it in
    context.Response.Write(...).

    I think this would be the best option.

    Could someone help me out?

    Thanks,
    Miguel
     
    shapper, Oct 15, 2006
    #1
    1. Advertising

  2. I hope i understood ur question.
    But u can just double click on the XML file
    Patrick
    "shapper" <> wrote in message
    news:...
    > Hello,
    >
    > I am using a XSL file to transform a XML file.
    > Then I want to display the XML file in browser as XML type.
    > I am working on an Asp.Net 2.0 HTTP Generic Handler (.ashx).
    >
    > My code is:
    >
    > Public Sub ProcessRequest(ByVal context As HttpContext) Implements
    > IHttpHandler.ProcessRequest
    >
    > Dim server As System.Web.HttpServerUtility =
    > System.Web.HttpContext.Current.Server
    > Dim docXml As XmlDocument = New XmlDocument
    > docXml.Load(server.MapPath("~/App_Data/Doc.Xml"))
    > Dim docXsl As XslCompiledTransform = New XslCompiledTransform
    > docXsl.Load(server.MapPath("~/App_Data/Doc.xsl"))
    > docXsl.Transform(docXml, Nothing,
    > HttpContext.Current.Response.Output)
    >
    >
    > ' context.Response.ContentType = "text/xml"
    > ' ??? context.Response.Write(...)
    >
    > End Sub
    >
    > I need to display the XML file in my browser as XML file.
    > With docXsl.Transform(docXml, Nothing,
    > HttpContext.Current.Response.Output) I am not doing it.
    >
    > Is there an option to make this hapening?
    >
    > Maybe if I save the result in a XML object and then place it in
    > context.Response.Write(...).
    >
    > I think this would be the best option.
    >
    > Could someone help me out?
    >
    > Thanks,
    > Miguel
    >
     
    Patrick.O.Ige, Oct 17, 2006
    #2
    1. Advertising

  3. shapper

    shapper Guest

    This is done at runtime.
    I don't want to save the result to a file
    I want to display the result in the brower ... yes, like i would get if
    i would open a xml file.

    Thanks,
    Miguel

    Patrick.O.Ige wrote:
    > I hope i understood ur question.
    > But u can just double click on the XML file
    > Patrick
    > "shapper" <> wrote in message
    > news:...
    > > Hello,
    > >
    > > I am using a XSL file to transform a XML file.
    > > Then I want to display the XML file in browser as XML type.
    > > I am working on an Asp.Net 2.0 HTTP Generic Handler (.ashx).
    > >
    > > My code is:
    > >
    > > Public Sub ProcessRequest(ByVal context As HttpContext) Implements
    > > IHttpHandler.ProcessRequest
    > >
    > > Dim server As System.Web.HttpServerUtility =
    > > System.Web.HttpContext.Current.Server
    > > Dim docXml As XmlDocument = New XmlDocument
    > > docXml.Load(server.MapPath("~/App_Data/Doc.Xml"))
    > > Dim docXsl As XslCompiledTransform = New XslCompiledTransform
    > > docXsl.Load(server.MapPath("~/App_Data/Doc.xsl"))
    > > docXsl.Transform(docXml, Nothing,
    > > HttpContext.Current.Response.Output)
    > >
    > >
    > > ' context.Response.ContentType = "text/xml"
    > > ' ??? context.Response.Write(...)
    > >
    > > End Sub
    > >
    > > I need to display the XML file in my browser as XML file.
    > > With docXsl.Transform(docXml, Nothing,
    > > HttpContext.Current.Response.Output) I am not doing it.
    > >
    > > Is there an option to make this hapening?
    > >
    > > Maybe if I save the result in a XML object and then place it in
    > > context.Response.Write(...).
    > >
    > > I think this would be the best option.
    > >
    > > Could someone help me out?
    > >
    > > Thanks,
    > > Miguel
    > >
     
    shapper, Oct 17, 2006
    #3
  4. Hi,

    shapper wrote:
    > This is done at runtime.
    > I don't want to save the result to a file
    > I want to display the result in the brower ... yes, like i would get if
    > i would open a xml file.
    >
    > Thanks,
    > Miguel


    I display dynamically generated XML content in the browser with this code:

    // Set the response's content type. It must be XML!
    context.Response.ContentType = "text/xml; charset=utf-8";
    context.Response.StatusCode = 200;

    // Save the XML document using the response's stream.
    docResponse.Save(
    new XmlTextWriter( context.Response.OutputStream,
    context.Request.ContentEncoding ) );

    where docResponse is an XmlDocument created for example like this (this
    example returns the server's date/time)

    XmlDocument docResponse = new XmlDocument();
    XmlElement elResponse = docResponse.CreateElement( "response" );
    docResponse.AppendChild( elResponse );

    XmlElement elCurrent = docResponse.CreateElement( "current" );
    string strDate = DateTime.Now.ToLongDateString();
    string strTime = DateTime.Now.ToLongTimeString();
    elCurrent.SetAttribute( "date", strDate );
    elCurrent.SetAttribute( "time", strTime );
    elResponse.AppendChild( elCurrent );

    See
    http://www.galasoft-lb.ch/mydotnet/articles/article-2006100601.aspx

    HTH,
    Laurent
    --
    Laurent Bugnion, GalaSoft
    Software engineering: http://www.galasoft-LB.ch
    Private/Malaysia: http://mypage.bluewin.ch/lbugnion
    Support children in Calcutta: http://www.calcutta-espoir.ch
     
    Laurent Bugnion, Oct 17, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. blank101
    Replies:
    2
    Views:
    539
    blank101
    Feb 5, 2005
  2. jkflens
    Replies:
    2
    Views:
    1,500
    jkflens
    May 30, 2006
  3. Stefan Schulze Frielinghaus

    Display raw XML file in HTML file via XSL

    Stefan Schulze Frielinghaus, Jun 25, 2008, in forum: XML
    Replies:
    2
    Views:
    2,958
    Stefan Schulze Frielinghaus
    Jun 29, 2008
  4. sed_y
    Replies:
    0
    Views:
    1,030
    sed_y
    Feb 15, 2012
  5. Erik Wasser
    Replies:
    5
    Views:
    469
    Peter J. Holzer
    Mar 5, 2006
Loading...

Share This Page