vbscript tries to read RSS feeds have issue of Sys

2019-09-18 06:46发布

问题:

I am trying to use a client's URL to shows feeds on our site. The problem that I am having is that it appears that their application was written in java, and the encoding of the XML response is ISO8859_1, an encoding which is not supported by the MSXML active x object. Please see this link for reference: http://support.microsoft.com/default.aspx?scid=kb;EN-US;q304625.

The problem is, I highly doubt that I will be able to change, or even request to change the encoding of the response xml. Is there another work around for this?

CODE

Function GetXmlDom(pUrl)
        Set GetXmlDom = Server.CreateObject("MSXML2.DOMDocument")
        GetXmlDom.async = False
        GetXmlDom.setProperty "ServerHTTPRequest", True
        GetXmlDom.load(pUrl)

End Function

It will first display all of the headers which seem fine. Then i get this error:

error code 1072896658 Reason System does not support the specified encoding. System error: -1072896658.

If i navigate to the same URL in my browser, it displays the XML document fine.

Can you please suggest a solution for same

Thanks, Rohit

回答1:

I highly doubt that I will be able to change, or even request to change the encoding of the response xml.

Well, it's broken. The IANA says that the canonical name for ISO-8859-1 is ISO-8859-1. and ISO8859_1 is not a legal alias for it. To practice good internet citizenship, you should request the change. Point out that it's broken, and ask for a fix. To practice good citizenship, your client should fix that bug.

ISO8859_1 is a name that was originally used, I think, within Java library code, as a name that mapped to ISO-8859-1. This usage was fine, although I don't understand the need for the mapping. But from there people assumed that the internal name Java uses is actually the encoding name - not true. It is really an alias known only to Java. And then that erroneous belief spread to other libraries and frameworks outside of Java that assumed incorrectly that if Java was using ISO8859_1 as an encoding name, it must be right. The bottom line is that ISO8859_1 should not be used in actual xml documents where an IANA encoding string is expected.


In the meantime...

If i navigate to the same URL in my browser, it displays the XML document fine.

That's not what I get. Using this as the rss source:

<?xml version="1.0" encoding="ISO8859_1"?>
<rss version="2.0">
  <channel>
<title>FeedForAll Sample Feed</title>
<description>RSS is a fascinating technology. ....</description>
 ...

I get this result in IE8:

To read it in vbscript, you need to replace that ISO8859_1 with ISO-8859-1 . This is pretty easy using the ServerHTTPRequest object.

Function UrlGet(url)
    Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP.6.0")
    xmlhttp.open "GET", url, False
    xmlhttp.send
    '' treat the output as plain text. We know it may be broken.
    UrlGet = xmlhttp.responseText
End Function


Dim url
url = "http://localhost/misc/broken.rss"

'' the above URL starts with an XML declaration of
''    <?xml version="1.0" encoding="ISO8859_1"?>
'' ... which is invalid, because ISO8859_1 is not a valid
'' name for an XML encoding.

Dim urlText
urlText = UrlGet(url)

'' replace the encoding with what we think it should be
urlText = Replace(urlText,"encoding=""ISO8859_1""","encoding=""ISO-8859-1""")

Set doc1 = CreateObject("Msxml2.DOMDocument.6.0")
doc1.async = False
doc1.preserveWhiteSpace= False ' True
doc1.loadXml(urlText)