I dont khow how to display the XML file "professional" way

Hi
I dont khow how to display the XML file "professional" way
(ie like VS 2005 span in / out ) can u help me
Thks a lot




Answer this question

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

    If you are talking about ASP.NET, one simple way is to make use of eXml Web server control with FriendlyXml property turned on.

  • Andrey Grigorev

    because you use DOM(XmlDocument) ,it will take much time when load "large" XML File ...
    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

    thks , but I want to use in WinForm ,please help me


  • I dont khow how to display the XML file "professional" way