我正在尝试将包含XML的字符串转换为可以在浏览器中显示的字符串。为此,我将字符串传递给以下函数:
Function HTMLDecode(sText)
Dim regEx
Dim matches
Dim match
sText = Replace(sText, Chr(34), """)
sText = Replace(sText, Chr(60), "<")
sText = Replace(sText, Chr(62), ">")
sText = Replace(sText, Chr(38), "&")
sText = Replace(sText, Chr(32), " ")
Set regEx= New RegExp
With regEx
.Pattern = "&#(\d+);" 'Match html unicode escapes
.Global = True
End With
Set matches = regEx.Execute(sText)
'Iterate over matches
For Each match in matches
'For each unicode match, replace the whole match, with the ChrW of the digits.
sText = Replace(sText, match.Value, ChrW(match.SubMatches(0)))
Next
HTMLDecode = sText
End Function
但是,当我打电话时,如下:
response.write HTMLDecode(strResponse)
转换发生但这是我在浏览器中看到的:
<?xml version="1.0"? >
而不是
<xml version="1.0"? >
发生在IE,FF&amp; Chrome所以我想它一定是我的代码 - 任何想法?
答案 0 :(得分:1)
尝试使用
Server.HTMLEncode(strResponse)
答案 1 :(得分:-1)