I am building an XML string programatically using the XmlWriter ...
sb = New StringBuilder()
writer = XmlWriter.Create(sb)
writer.WriteStartDocument()
writer.WriteStartElement("root")
writer.WriteStartElement("element1")
writer.WriteAttributeString("myattribute", "myvalue")
writer.WriteEndElement()
writer.WriteEndElement()
writer.WriteEndDocument()
writer.Flush()
myTextBox.text = "<pre>" & Return sb.ToString() & "</pre>"
I want to be able to output the XML to a TextBox control on a ASP.NET webform. When I do output the XML I don't get any line breaks or indentation in the XML. The XmlWriter
does not seem to have any properties to set formatting. Is there anyway to retain formatting and indentation? Thank you.
Use a XmlWriterSettings class instance to specify the use of indentations and line breaks and then pass it into the xmlWriter's Create method. See the documentation here.