Format XML text in a RTB

  • Thread starter Thread starter CNU
  • Start date Start date
C

CNU

Hi,
I have a richtextbox control that displays some xml data
either by loading from a file or by copy-paste in
plaintext format. So, it is displayed without any
formatting or indentation. Now, I want to display it in a
more readable fashion. So, I want to provide an option
like "Format Whole Document" (like the one in VS .NET).
Is there any way to do this?

Regards.
 
Hi,
You can use the System.Xml.XmlDocument for such purposes. For example:

XmlDocument doc = new XmlDocument();
doc.LoadXml("<mytag><mysubtag></mysubtag></mytag>");
doc.Save(Console.Out);

This code will print given XML in formatted form:

<?xml version="1.0" encoding="cp866"?>
<mytag>
<mysubtag>
</mysubtag>
</mytag>

So, you can load your XML data from the richtextbox control into the
XmlDocument, save document into the memory stream and replace richtextbox
control text with saved XML.

--
Andrew Gnenny
pulsar2003@/no-spam/email.ru (Please remove /no-spam/ for reply)
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE
 

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

Back
Top