服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|

服务器之家 - 编程语言 - ASP教程 - ASP常用函数:XMLEncode

ASP常用函数:XMLEncode

2019-10-25 11:09asp教程网 ASP教程

ASP常用函数:XMLEncode

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

原理:

Character

Converted To

"

"

'

'

&

&

<

<

>

>

 

代码
<%
Function XMLEncode(byVal sText)
    sText = Replace(sText, "&" , "&")
    sText = Replace(sText, "<" , "<")
    sText = Replace(sText, ">" , ">")
    sText = Replace(sText, "'" , "'")
    sText = Replace(sText, """", """)
    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
%>

延伸 · 阅读

精彩推荐