欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

ASP常用函数:XMLEncode

程序员文章站 2023-12-04 18:15:04
输出rss和xml时经常用到,和htmlencode还不完全一样 原理: character converted to " "...

输出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
%>