ASP常用函数:XMLEncode
程序员文章站
2023-11-16 21:49:34
输出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
%>