Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Formatting XML for display
Message
De
30/08/2005 12:20:23
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
XML
Titre:
Formatting XML for display
Versions des environnements
Environment:
C# 1.1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Divers
Thread ID:
01045196
Message ID:
01045196
Vues:
54
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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform