XmlWriterSettings.Indent Property
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Gets or sets a value indicating whether to indent elements.
Assembly: System.Xml (in System.Xml.dll)
Property Value
Type: System.Booleantrue to write individual elements on new lines and indent; otherwise false. The default is false.
This property only applies to XmlWriter instances that output text content; otherwise, this setting is ignored.
The elements are indented as long as the element does not contain mixed content. Once the WriteString or WriteWhitespace method is called to write out a mixed element content, the XmlWriter stops indenting. The indenting resumes once the mixed content element is closed.
StringBuilder output = new StringBuilder(); XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.OmitXmlDeclaration = true; settings.NewLineOnAttributes = true; using (XmlWriter writer = XmlWriter.Create(output, settings)) { writer.WriteStartElement("order"); writer.WriteAttributeString("orderID", "367A54"); writer.WriteAttributeString("date", "2001-05-03"); writer.WriteElementString("price", "19.95"); writer.WriteEndElement(); writer.Flush(); } OutputTextBlock.Text = output.ToString();