【问题标题】:Invalid character in the given encoding when parsing rss feed解析 rss 提要时给定编码中的无效字符
【发布时间】:2012-08-31 08:57:43
【问题描述】:

我正在解析来自另一台服务器的 rss 提要并显示在中继器中。 但是有错误:给定编码中的字符无效。 代码如下:

Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        'Create a WebRequest
        Dim rssReq As WebRequest = WebRequest.Create("http://www.freelancer.com/rss/affiliatejob_mamboking_NET.xml")
        'Create a Proxy
        Dim px As New WebProxy("http://www.freelancer.com/rss/affiliatejob_mamboking_NET.xml", True)
        'Assign the proxy to the WebRequest
        rssReq.Proxy = px
        'Set the timeout in Seconds for the WebRequest
        rssReq.Timeout = 5000
        Try
            'Get the WebResponse
            Dim rep As WebResponse = rssReq.GetResponse()
            'Read the Response in a XMLTextReader
            Dim xtr As New XmlTextReader(rep.GetResponseStream())
            'Create a new DataSet
            Dim ds As New DataSet()
            'Read the Response into the DataSet
            ds.ReadXml(xtr)
            'Bind the Results to the Repeater
            rssFreelance.DataSource = ds.Tables(0)
            rssFreelance.DataBind()
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

当我看到 xml 的源代码时,它会显示 utf-8 编码。

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="http://www.freelancer.com/content/rss.xsl" ?><rss version="2.0" xmlns:coop="http://www.google.com/coop/namespace">

【问题讨论】:

    标签: xml vb.net character-encoding rss


    【解决方案1】:
    Imports System.Web
    WebUtility.HtmlDecode(response)
    

    其中 response 是您要解码的实际文本、说明标题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-05
      • 1970-01-01
      • 2011-02-09
      • 2014-10-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多