You may also do as simple as this...
XmlDocument dom = new XmlDocument();
dom.Load("not-pretty.xml");
dom.Save("pretty.xml");
If you don't want any I/O operations, you may also Save to TextWriter or
Stream
Thanks
Pranav
"Kevin Burton" <KevinBurton@discussions.microsoft.com> wrote in message
news:9937F411-11AB-44DD-B1E4-B2C022D9FF24@microsoft.com...[color=blue]
> This was precisly what I was looking for. Thank you.
>
> "Kent Boogaart" wrote:
>[color=green]
>> I think this is what you want. Probably a more efficient way to do it...
>>
>> using System;
>>
>> using System.IO;
>>
>> using System.Xml;
>>
>> namespace XmlTest
>>
>> {
>>
>> class Class1
>>
>> {
>>
>> [STAThread]
>>
>> static void Main(string[] args)
>>
>> {
>>
>> using (StringWriter stringWriter = new StringWriter())
>>
>> {
>>
>> XmlDocument doc = new XmlDocument();
>>
>> //get your document
>>
>> doc.LoadXml("<root><element
>> foo=\"bar\"><child></child></element></root>");
>>
>> //create reader and writer
>>
>> XmlNodeReader xmlReader = new XmlNodeReader(doc);
>>
>> XmlTextWriter xmlWriter = new XmlTextWriter(stringWriter);
>>
>> //set formatting options
>>
>> xmlWriter.Formatting = Formatting.Indented;
>>
>> xmlWriter.Indentation = 1;
>>
>> xmlWriter.IndentChar = '\t';
>>
>> //write the document formatted
>>
>> xmlWriter.WriteNode(xmlReader, true);
>>
>> Console.WriteLine(stringWriter.ToString());
>>
>> }
>>
>>
>> Console.ReadLine();
>>
>> }
>>
>> }
>>
>> }
>>
>>
>>
>> Cheers,
>>
>> Kent
>>
>>
>>
>> "Kevin Burton" <KevinBurton@discussions.microsoft.com> wrote in message
>> news:6211C93E-BD9E-4157-815E-368F7222C62D@microsoft.com...[color=darkred]
>> >
>> > I want to put the "pretty" XML in an .NET RTF Text box. Is there an
>> > XSLT
>> > transform or some .NET Framework function that I can call? In VB there
>> > is
>> > the
>> > "Indent" function with the MSXML toolkit, but I am using C#. I would
>> > like
>> > a
>> > more direct approach. Spawning IE and trying to get the text out would
>> > be
>> > too
>> > cumbersome. I think that an XSLT transform will be more direct. I just
>> > don't
>> > have the time right now to write it. Since this is used so frequently I
>> > was
>> > hoping that there might already be a Framework function to do this.
>> >
>> > Kevin
>> >
>> > "Peter IEFlynn" wrote:
>> >
>> >> Kevin Burton wrote:
>> >>
>> >> > I am sure this has been asked enough to warrant an FAQ but I could
>> >> > not
>> >> > find it.
>> >> >
>> >> > Does anyone have some code and maybe an XSLT stylesheet that would
>> >> > allow
>> >> > me to transform an XML string to a "pretty" version (nodes indented
>> >> > on
>> >> > separate lines, etc.)?
>> >>
>> >> Open it in IE or Firefox.
>> >> Or use an XML editor that has an indent-and-reformat function.
>> >>
>> >> ///Peter
>> >> --
>> >> XML FAQ:
http://xml.silmaril.ie/
>> >>
>> >>
>> >>[/color]
>>
>>
>>[/color][/color]