How to display xml string on asp.net page [modified]
-
Hi, From a link I open up a popUp window where I want to display an xml, exactly the way for instance IE does when you open an xml document from file (expanded with parents and childs). In my
Page_Load
method (in the popUp window) I retrieve the xml string via a web service and then I want it to be displayed. But how? I tried the following code:string xmlString = rq.GetErrorTextByID(id); //retrieve the xml from web service - works fine.
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlString);
doc.Save(Server.MapPath("message.xml"));
Response.Redirect("message.xml");This works fine, but of course it physically creates the
message.xml
file on disk and I don't want that. I want the xml to be shown the same way as this code does, but I don't want the file to be created. This might be a simple task, but I haven't worked with asp.net for that long :| Any ideas/suggestions?modified on Wednesday, September 23, 2009 10:38 AM
-
Hi, From a link I open up a popUp window where I want to display an xml, exactly the way for instance IE does when you open an xml document from file (expanded with parents and childs). In my
Page_Load
method (in the popUp window) I retrieve the xml string via a web service and then I want it to be displayed. But how? I tried the following code:string xmlString = rq.GetErrorTextByID(id); //retrieve the xml from web service - works fine.
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlString);
doc.Save(Server.MapPath("message.xml"));
Response.Redirect("message.xml");This works fine, but of course it physically creates the
message.xml
file on disk and I don't want that. I want the xml to be shown the same way as this code does, but I don't want the file to be created. This might be a simple task, but I haven't worked with asp.net for that long :| Any ideas/suggestions?modified on Wednesday, September 23, 2009 10:38 AM
You mean you need to write the content of message.xml to your browser?? Use this code :
Response.Clear();
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlString);
doc.Save(Response.OutputStream);
Response.Flush();
Response.Close();I think this is what you need. :rose::rose:
Abhishek Sur
My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB
**Don't forget to click "Good Answer" if you like to.
-
You mean you need to write the content of message.xml to your browser?? Use this code :
Response.Clear();
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlString);
doc.Save(Response.OutputStream);
Response.Flush();
Response.Close();I think this is what you need. :rose::rose:
Abhishek Sur
My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB
**Don't forget to click "Good Answer" if you like to.
Yes, this was exactly what I was looking for. Thank you! Though I had to add one more line of code to get the string to show as XML. The code snippet I use is this:
Response.Clear();
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlString);
doc.Save(Response.OutputStream);
Response.ContentType = "text/xml"; // -> Added this line to show the XML properly.
Response.Flush();
Response.Close(); -
Yes, this was exactly what I was looking for. Thank you! Though I had to add one more line of code to get the string to show as XML. The code snippet I use is this:
Response.Clear();
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlString);
doc.Save(Response.OutputStream);
Response.ContentType = "text/xml"; // -> Added this line to show the XML properly.
Response.Flush();
Response.Close();Great... Thanks for the update as well. . ;) ;) I just overlooked the
contentType
.Abhishek Sur
My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB
**Don't forget to click "Good Answer" if you like to.