Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Formatting XML for display
Message
From
30/08/2005 13:31:13
Keith Payne
Technical Marketing Solutions
Florida, United States
 
 
To
30/08/2005 12:20:23
General information
Forum:
ASP.NET
Category:
XML
Environment versions
Environment:
C# 1.1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Miscellaneous
Thread ID:
01045196
Message ID:
01045236
Views:
22
The easiest way to do this is to launch a new browser window using javascript [document.open()], set the content type to XML, and write the XML to the Response stream. The web browser will then control the rendering of the XML. In IE, you get expandable nodes and color coding.

>

Hello All,
>
>I have a Web Service that accepts XML input and returns XML. The XML will be consumed by a third party.
>
>I have designed a simple ASP page to hit the web service. I have two textboxes on the form - one for input, and one that displays the output from the web service. The data (xml) coming back is displayed in the textbox, but I want to format it (indentation, line feeds, etc.) to make it easier to read. Is there an easy way to do this? I know in the IDE if I hit CTRL+K, CTRL+D, the xml is formatted. I want to do this in code on the ASP page. The following is what I am doing now to format the XML:
>
>
>    private string FormatXML(string xmlString)
>    {
>      string retVal = "";
>      XmlDocument doc = new XmlDocument();
>      doc.PreserveWhitespace = true;
>      doc.LoadXml(xmlString);
>      System.IO.MemoryStream ms = new MemoryStream();
>      XmlTextWriter xtw = new XmlTextWriter(ms, new System.Text.UTF8Encoding(false));
>      xtw.Formatting = Formatting.Indented;
>      xtw.Indentation = 4;
>      doc.Save(xtw);
>      byte[] xmlBytes = ms.ToArray();
>      foreach (byte b in xmlBytes)
>      {
>        retVal += (char)b;
>      }
>      return retVal;
>    }
>
>
>This works just fine for a small amount (10K) of data returned, but when the output is aroung 100K or so, it takes forever. Is there an alternative way of formatting this XML in the textbox?
>
>Thanks for you help,
>Pat Moran
Previous
Reply
Map
View

Click here to load this message in the networking platform