Software Development Network>> .NET Development>> I dont khow how to display the XML file "professional" way
Try something like this...
XmlDocument doc = new XmlDocument();
doc.LoadXml("<Collection><Book Id='1'><Title>Principle of Relativity</Title><Author>Albert Einstein</Author><Genre>Physics</Genre></Book> <Book Id='2'><Title>Cosmos</Title><Author>Carl Sagan</Author><Genre>Cosmology</Genre></Book></Collection>");
MemoryStream ms = new MemoryStream();
XmlTextWriter w = new XmlTextWriter(ms, System.Text.Encoding.UTF8);
w.Formatting = Formatting.Indented;
doc.Save(w);
w.Flush();
ms.Position = 0;
StreamReader sr = new StreamReader(ms);
string a = sr.ReadToEnd();
Console.WriteLine(a);
You can read XML with XmlTextreader and write it to the output using XmlWriter.
set.Indent =
This XmlWriter will indent XML "profecionaly".
I dont khow how to display the XML file "professional" way
caldo_123
Try something like this...
XmlDocument doc = new XmlDocument();
doc.LoadXml("<Collection><Book Id='1'><Title>Principle of Relativity</Title><Author>Albert Einstein</Author><Genre>Physics</Genre></Book> <Book Id='2'><Title>Cosmos</Title><Author>Carl Sagan</Author><Genre>Cosmology</Genre></Book></Collection>");
MemoryStream ms = new MemoryStream();
XmlTextWriter w = new XmlTextWriter(ms, System.Text.Encoding.UTF8);
w.Formatting = Formatting.Indented;
doc.Save(w);
w.Flush();
ms.Position = 0;
StreamReader sr = new StreamReader(ms);
string a = sr.ReadToEnd();
Console.WriteLine(a);
Patrick Cauldwell
You can read XML with XmlTextreader and write it to the output using XmlWriter.
XmlWriterSettings set = new XmlWriterSettings();set.Indent =
true; XmlWriter w = XmlWriter.Create(Console.Out, set);This XmlWriter will indent XML "profecionaly".
cbarru1
Andrey Grigorev
and when I load XML by using "For xml" ( SQL2000 ) ,how can I save it to keep
format of XML file to display more easy ....
BCullenward