Friday, March 11, 2011

Simple XML Encoder.

Hi All,

I had frequently convert some XML / HTML text in to an encoded text [eg: If you have to post it in a blog], so I came up with this simple [very simple :)] .NET XML encoder. Enjoy!!


[Please let me know what you think in the comments section]


Public Class Form1

    Private Sub txtPlainText_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPlainText.TextChanged
        Dim strPlainText, strXMLencoded As String
        strPlainText = txtPlainText.Text
        strXMLencoded = System.Web.HttpUtility.HtmlEncode(strPlainText)
        txtDestination.Text = strXMLencoded

    End Sub

    Private Sub cmdCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCopy.Click
        Clipboard.SetText(txtDestination.Text.Trim())
    End Sub

    Private Sub btnConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConvert.Click
        Dim strPlainText, strXMLencoded As String
        strPlainText = txtPlainText.Text
        strXMLencoded = System.Web.HttpUtility.HtmlEncode(strPlainText)
        txtDestination.Text = strXMLencoded
    End Sub
End Class

No comments: