B4A Class EscapeXml - Code snippet

Discussion in 'Additional libraries, classes and official updates' started by Erel, Dec 15, 2013.

  1. Erel

    Erel Administrator Staff Member Licensed User

    The following code escapes the five XML entities. If you are using a library such as XmlBuilder then it is not required to escape the text as the XML writer will do it automatically.

    However if you use a template for the XML file and need to fill some of the fields then this code can be helpful.

    Public Sub EscapeXml(Raw As StringAs String
    Dim sb As StringBuilder
    For i = 0 To Raw.Length - 1
    Dim c As Char = Raw.CharAt(i)
    Select c
    Case QUOTE
    Case "'"
    Case "<"
    Case ">"
    Case "&"
    Case Else
    End Select
    Return sb.ToString
    End Sub
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice