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" <Ke*********@discussions.microsoft.com> wrote in message
news:62**********************************@microsof t.com...
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/