Connecting Tech Pros Worldwide Help | Site Map

Indent xml

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 12th, 2005, 02:20 AM
guy
Guest
 
Posts: n/a
Default Indent xml

Is there a simple way to indent xml with dotnet? SQL Server returns a long xml string that is hard
to read.

  #2  
Old November 12th, 2005, 02:20 AM
Oleg Tkachenko [MVP]
Guest
 
Posts: n/a
Default Re: Indent xml

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
  #3  
Old November 12th, 2005, 02:20 AM
guy
Guest
 
Posts: n/a
Default Re: Indent xml

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.
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.