ASP常用函数:XMLEncode

编程学习 2021-07-05 10:58www.dzhlxh.cn编程入门

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

原理:

Character Converted 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
%>

Copyright © 2016-2025 www.dzhlxh.cn 金源码 版权所有 Power by

网站模板下载|网络推广|微博营销|seo优化|视频营销|网络营销|微信营销|网站建设|织梦模板|小程序模板