当前位置:首页 > ASP教程 > 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
%>


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!