Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • Leaders
Posted

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.

[sIGPIC]e[/sIGPIC]
Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...