Display XML file

S

shapper

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
 
P

Patrick.O.Ige

I hope i understood ur question.
But u can just double click on the XML file
Patrick
 
S

shapper

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
 
L

Laurent Bugnion

Hi,
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,742
Latest member
AshliMayer

Latest Threads

Top