CLR: strip discouraged characters from a string for xml vb.net

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports Microsoft.SqlServer.Server
Partial Public Class UserDefinedFunctions
”’ <summary>
”’ removes discouraged characters
”’ obsolete, sobald LogicBase.CLR überall aktualisiert wurde => Version > 1.0.3804.21154
”’ </summary>
”’ <param name=”Content”>string for xml</param>
”’ <returns>clean SqlString</returns>
”’ <remarks>
”’ Response is not well-formed XML System.Xml.XmlException XML System.Xml.XmlException , hexadecimal value 0x2, is an invalid character.
”’ see http://www.w3.org documentation:
”’ </remarks>
<Microsoft.SqlServer.Server.SqlFunction()> _
Public Shared Function udfLBXMLRemoveDiscouragedCharacters(ByVal Content As String) As SqlString
Dim result As New System.Text.StringBuilder()
‘current character
Dim cC As Char
If Content Is Nothing OrElse Content = String.Empty Then
Return String.Empty
End If
For i As Integer = 0 To Content.Length – 1
cC = Content(i)
If (AscW(cC) = &H9 OrElse AscW(cC) = &HA OrElse AscW(cC) = &HD) _
OrElse ((AscW(cC) >= &H20) AndAlso (AscW(cC) <= &HD7FF)) _
OrElse ((AscW(cC) >= &HE000) AndAlso (AscW(cC) <= &HFFFD)) _
OrElse ((AscW(cC) >= &H10000) AndAlso (AscW(cC) <= &H10FFFF)) Then
result.Append(cC)
End If
Next
Return New SqlString(result.ToString())
End Function
End Class

Imports SystemImports System.DataImports System.Data.SqlClientImports System.Data.SqlTypesImports Microsoft.SqlServer.Server

Partial Public Class UserDefinedFunctions    ”’ <summary>    ”’ removes discouraged characters     ”’ obsolete, sobald LogicBase.CLR überall aktualisiert wurde => Version > 1.0.3804.21154    ”’ </summary>    ”’ <param name=”Content”>string for xml</param>    ”’ <returns>clean SqlString</returns>    ”’ <remarks>    ”’ Response is not well-formed XML System.Xml.XmlException XML System.Xml.XmlException , hexadecimal value 0x2, is an invalid character.    ”’ see http://www.w3.org documentation:    ”’ http://www.w3.org/TR/2008/REC-xml-20081126/#charsets    ”’ http://www.w3.org/TR/xml11/#charsets    ”’ </remarks>    <Microsoft.SqlServer.Server.SqlFunction()> _    Public Shared Function udfLBXMLRemoveDiscouragedCharacters(ByVal Content As String) As SqlString
Dim result As New System.Text.StringBuilder()
‘current character        Dim cC As Char
If Content Is Nothing OrElse Content = String.Empty Then            Return String.Empty        End If
For i As Integer = 0 To Content.Length – 1
cC = Content(i)
If (AscW(cC) = &H9 OrElse AscW(cC) = &HA OrElse AscW(cC) = &HD) _             OrElse ((AscW(cC) >= &H20) AndAlso (AscW(cC) <= &HD7FF)) _             OrElse ((AscW(cC) >= &HE000) AndAlso (AscW(cC) <= &HFFFD)) _             OrElse ((AscW(cC) >= &H10000) AndAlso (AscW(cC) <= &H10FFFF)) Then                result.Append(cC)            End If
Next
Return New SqlString(result.ToString())
End FunctionEnd Class

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s