363,924 Members | 2585 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

Indent xml

guy
P: n/a
guy
Is there a simple way to indent xml with dotnet? SQL Server returns a long xml string that is hard
to read.
Nov 12 '05 #1
Share this Question
Share on Google+
2 Replies


Oleg Tkachenko [MVP]
P: n/a
Oleg Tkachenko [MVP]
guy wrote:
[color=blue]
> Is there a simple way to indent xml with dotnet? SQL Server returns a long xml string that is hard
> to read.[/color]

XmlReader r = new XmlTextReader(new StringReader(myXML));
StringWriter sw = new StringWriter();
XmlTextWriter w = new XmlTextWriter(sw);
w.Formatting = Formatting.Indented;
while (r.Read())
w.WriteNode(r, false);
w.Close();
r.Close();
Console.WriteLine(sw.ToString());
--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #2

guy
P: n/a
guy
On Tue, 11 May 2004 12:34:50 +0200, "Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote:
[color=blue]
>guy wrote:
>[color=green]
>> Is there a simple way to indent xml with dotnet? SQL Server returns a long xml string that is hard
>> to read.[/color]
>
>XmlReader r = new XmlTextReader(new StringReader(myXML));
>StringWriter sw = new StringWriter();
>XmlTextWriter w = new XmlTextWriter(sw);
>w.Formatting = Formatting.Indented;
>while (r.Read())
> w.WriteNode(r, false);
>w.Close();
>r.Close();
>Console.WriteLine(sw.ToString());[/color]

I will try it. Thank you for your help.
Nov 12 '05 #3

Post your reply

Help answer this question



Didn't find the answer to your .NET Framework question?

You can also browse similar questions: .NET Framework