XML formatter

In this chapter you will learn:

  1. How to use XML formatter to format XML

Format XML

using System;//from j a v a 2  s  .  c o  m
using System.Collections;
using System.Data;
using System.Xml;


class MainClass{
  public static void Main(){
    XmlDocument doc = new XmlDocument();
    // read 
    doc.Load( "Sample.xml" );
    Console.WriteLine(doc.OuterXml);

    // write
    XmlTextWriter tw = new XmlTextWriter( "testOut.xml", null );
  tw.Formatting = Formatting.Indented;
  tw.Indentation = 4;
  doc.Save( tw );
  tw.Close();
        
  }

}

Next chapter...

What you will learn in the next chapter:

  1. How to serialize object to XML
Home » C# Tutorial » XML
Parse XML file
Parse XML String
Parse XML from URL
Element create
Attribute create
Comments create
XProcessingInstruction
XmlReader
Read double value from XML
XmlReader
XmlReaderSettings
XML formatter
XmlSerializer
XmlTextReader
XmlTextWriter
XmlWriter
XmlWriterSettings
Output XML to console