davearia Posted November 30, 2006 Posted November 30, 2006 Hi, I am putting a xml document into a textbox. The only problem is that all the indentation etc in the original document is lost when it is put in the textbox. So your left with an ugly mess of text, instead of a nicely formatted view. I have tried using a richTextBox instead but got the same results. Is there some way I can acheive this? Cheers, Davearia. :D :D :D Quote
Leaders snarfblam Posted November 30, 2006 Leaders Posted November 30, 2006 How are you loading the XML into the TextBox? And are you sure that the document you are loading is formatted (what is the source of the document)? You might want to consider using the XML classes that come with .Net to load and parse the XML so that you can output it formatted however you like. Quote [sIGPIC]e[/sIGPIC]
davearia Posted November 30, 2006 Author Posted November 30, 2006 Here is what I used in the end: Public Sub showXML(ByVal xmlDoc As XmlDocument) Dim ms As System.IO.MemoryStream ms = FormatXMLDoc(xmlDoc) RichTextBox1.Text = ByteArrayToString(ms.GetBuffer) Me.ShowDialog() End Sub Private Function FormatXMLDoc(ByVal xmlDoc As XmlDocument) As System.IO.MemoryStream Dim retVal As New System.IO.MemoryStream Dim writer As XmlTextWriter = New XmlTextWriter(retVal, New System.Text.ASCIIEncoding) writer.Formatting = Formatting.Indented writer.Indentation = 1 writer.IndentChar = CChar(vbTab) xmlDoc.WriteTo(writer) writer.Flush() writer.Close() Return retVal End Function Private Function ByteArrayToString(ByVal ByteArray As Byte()) As String Return System.Text.Encoding.UTF8.GetString(ByteArray) End Function Cheers, Dave. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.