我正在尝试将包含 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 和 Chrome 中,所以我想这一定是我的代码 - 有什么想法吗?