Connecting Tech Pros Worldwide Help | Site Map

Indent xml

  #1  
Old November 12th, 2005, 03:20 AM
guy
Guest
 
Posts: n/a
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, 03:20 AM
Oleg Tkachenko [MVP]
Guest
 
Posts: n/a

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, 03:20 AM
guy
Guest
 
Posts: n/a

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.
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple XML Import into SQL 2005 raysot answers 0 November 27th, 2007 10:48 PM
Convert raw data to XML elrondrules@gmail.com answers 8 January 30th, 2007 11:25 PM
Xml indent problem @cl answers 2 September 14th, 2006 02:45 AM
Indent won't work in XSLT cawoodm@gmail.com answers 2 September 28th, 2005 12:45 AM