首页 > 编程 > ASP > 正文

ASP常用函数:XMLEncode

2020-07-27 13:16:25
字体:
来源:转载
供稿:网友

输出RSS和XML时经常用到,和HTMLEncode还不完全一样

原理:

CharacterConverted To
""
''
&&
<&lt;
>&gt;

代码
<%
Function XMLEncode(byVal sText)
    sText = Replace(sText, "&" , "&amp;")
    sText = Replace(sText, "<" , "&lt;")
    sText = Replace(sText, ">" , "&gt;")
    sText = Replace(sText, "'" , "&apos;")
    sText = Replace(sText, """", "&quot;")
    XMLEncode = sText
End Function
%>
还有个:
<%
Public Function XmlEncode(ByVal strText As String) As String
    Dim aryChars() As Variant
    aryChars = Array(38, 60, 62, 34, 61, 39)
    Dim i As Integer
    For i = 0 To UBound(aryChars)
        strText = Replace(strText, Chr(aryChars(i)), "&#" & aryChars(i) & ";")
    Next
    XmlEncode = strText
End Function
%>

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表