yuanweisen

 

Excel数据转xml过滤特殊字符

'过滤特殊字符
Public Function XmlEncode(sStr)
    If Trim(sStr) = "" Or IsNull(sStr) Then
        XmlEncode = ""
        Exit Function
    End If
    sStr = Trim(sStr)

    Dim i
    i = 0
   
    Dim sRet
    sRet = ""
    '遍历传入的每个字符,如果遇到特殊字符,则替换成该字符的编码
    For i = 1 To Len(sStr)
        Select Case Mid(sStr, i, 1)
            Case "&"
                sRet = sRet & "&"
            Case "'"
                sRet = sRet & "'"
            Case "\"""
                sRet = sRet & "&quot"
            Case "<"
                sRet = sRet & "&lt;"
            Case ">"
                sRet = sRet & "&gt;"
            Case Else
                sRet = sRet & Mid(sStr, i, 1)
        End Select
    Next
    XmlEncode = sRet

End Function

posted on 2009-01-06 17:08    阅读(546)  评论(0编辑  收藏  举报

导航