System.Xml.XmlTextWriter.Formatting Property

Indicates how the output is formatted.

Syntax

public Formatting Formatting { get; set; }

Value

One of the members of the System.Xml.Formatting enumeration. The default is Formatting.None (no special formatting).

Remarks

Note:

In the dnprdnext release, the recommended practice is to create System.Xml.XmlWriter instances using the erload:System.Xml.XmlWriter.Create method and the System.Xml.XmlWriterSettings class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

If the Indented option is set, child elements are indented using the XmlTextWriter.Indentation and XmlTextWriter.IndentChar properties. Only element content is indented. The following C# code writes out HTML elements including mixed content:

Example

 XmlTextWriter w = new XmlTextWriter(Console.Out); 
  w.Formatting = Formatting.Indented; 
  w.WriteStartElement("ol"); 
  w.WriteStartElement("li"); 
  w.WriteString("The big "); // This means "li" now has a mixed content model.
  w.WriteElementString("b", "E"); 
  w.WriteElementString("i", "lephant"); 
  w.WriteString(" walks slowly."); 
  w.WriteEndElement(); 
  w.WriteEndElement();

The above code produces the following output:

Example

 <ol> 
   <li>The big <b>E</b><i>lephant</i> walks slowly.</li> 
 </ol>

When this is viewed in HTML no white space appears between the bold and italic elements. In fact, in this example, if indenting was added between these elements the word "Elephant" would be incorrectly broken.

Note:

Writing any text content, excluding String.Empty puts that element into mixed content mode. Child elements do not inherit this "mixed" mode status. A child element of a "mixed" element does indenting, unless it is also contains "mixed" content. Element content (http://www.w3.org/TR/1998/REC-xml-19980210#sec-element-content) and mixed content (http://www.w3.org/TR/1998/REC-xml-19980210#sec-mixed-content) are defined according to the XML 1.0 definitions of these terms.

Requirements

Namespace: System.Xml
Assembly: System.Xml (in System.Xml.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0