Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to display xml string on asp.net page [modified]

How to display xml string on asp.net page [modified]

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netsysadminxmltutorial
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Calla
    wrote on last edited by
    #1

    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

    A 1 Reply Last reply
    0
    • C Calla

      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

      A Offline
      A Offline
      Abhishek Sur
      wrote on last edited by
      #2

      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.

      C 1 Reply Last reply
      0
      • A Abhishek Sur

        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.

        C Offline
        C Offline
        Calla
        wrote on last edited by
        #3

        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();

        A 1 Reply Last reply
        0
        • C Calla

          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();

          A Offline
          A Offline
          Abhishek Sur
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups