vbscript create-convert xml with special characters -
i'm creating xml file in .vbs file node values following,
<car>david's</car> <company>mannar & co.</company> while parsing xml, find issues &, etc.
i want convert all possible xml special characters encoded characters(with a function or something) while parsing original content.
thanking you.
based on comment of op here version made myself, couldn't find reliable one, think covers possible ascii characters
function html_encode(byval string) dim tmp, tmp = string = 160 255 tmp = replace(tmp, chr(i), "&#" & & ";") next tmp = replace(tmp, chr(34), """) tmp = replace(tmp, chr(39), "'") tmp = replace(tmp, chr(60), "<") tmp = replace(tmp, chr(62), ">") tmp = replace(tmp, chr(38), "&") tmp = replace(tmp, chr(32), " ") html_encode = tmp end function function html_decode(byval encodedstring) dim tmp, tmp = encodedstring tmp = replace(tmp, """, chr(34) ) tmp = replace(tmp, "'", chr(39)) tmp = replace(tmp, "<" , chr(60) ) tmp = replace(tmp, ">" , chr(62) ) tmp = replace(tmp, "&" , chr(38) ) tmp = replace(tmp, " ", chr(32) ) = 160 255 tmp = replace(tmp, "&#" & & ";", chr(i)) next html_decode = tmp end function str = "this !@#± & test!" wscript.echo html_encode(str) '=> this !@#&#177; is a & test! wscript.echo html_decode(html_encode(str)) '=> !@#± & test!
Comments
Post a Comment