解析XML时,下载DTD时出现错误

问题描述 投票:1回答:2

我正在努力 vb.net 我创建了一个项目,我已经创建了一个动态新闻tiker。

代码 :

Imports System.ServiceModel.Syndication
Imports System.Xml

Partial Class DynamicTicker
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'Get the latest syndicated content from my Twitter feed!
        Dim myTweets As SyndicationFeed = SyndicationFeed.Load(XmlReader.Create("https://twitter.com/ashuthinks"))

        'Bind myTweets to the ListView
        lvTweets.DataSource = myTweets.Items
        lvTweets.DataBind()
    End Sub

    Protected Function FormatSummary(ByVal summary As String) As String
        Const SummaryHeader As String = "ScottOnWriting: "

        'Remove the leading "ScottOnWriting: "
        If summary.StartsWith(SummaryHeader) Then
            Return summary.Substring(SummaryHeader.Length)
        End If
    End Function

    Protected Function FormatPubDate(ByVal pubDate As DateTime) As String
        Return pubDate.ToString("h:mm, MMM d")
    End Function

End Class

但这给我和以下错误。

由于安全原因,在这个XML文档中禁止使用DTD。要启用DTD处理,请将XmlReaderSettings上的DtdProcessing属性设置为Parse,并将设置传入XmlReader.Create方法。

我应该在我的代码中哪里提到设置?

.net xml vb.net xml-parsing
2个回答
0
投票
Dim settings As XmlReaderSettings = new XmlReaderSettings()
settings.DtdProcessing = DtdProcessing.Parse;
Dim myTweets As SyndicationFeed =     SyndicationFeed.Load(XmlReader.Create("https://twitter.com/ashuthinks"),settings)

对不起,如果我的语法不对,不怎么写VB.NET代码。


0
投票
Dim settings As New XmlReaderSettings
   settings.DtdProcessing = DtdProcessing.Parse
   settings.ValidationType = ValidationType.DTD
   Dim xmlR = XmlReader.Create(Currentfile, settings)
© www.soinside.com 2019 - 2024. All rights reserved.