當前位置: 首頁>>代碼示例>>VB.NET>>正文


VB.NET XmlUrlResolver類代碼示例

本文整理匯總了VB.NET中System.Xml.XmlUrlResolver的典型用法代碼示例。如果您正苦於以下問題:VB.NET XmlUrlResolver類的具體用法?VB.NET XmlUrlResolver怎麽用?VB.NET XmlUrlResolver使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了XmlUrlResolver類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。

示例1: XmlUrlResolver

' Create an XmlUrlResolver with default credentials.
Dim resolver As New XmlUrlResolver()
resolver.Credentials = CredentialCache.DefaultCredentials

' Create the reader.
Dim settings As New XmlReaderSettings()
settings.XmlResolver = resolver
Dim reader As XmlReader = _
   XmlReader.Create("http://serverName/data/books.xml", settings)
開發者ID:VB.NET開發者,項目名稱:System.Xml,代碼行數:9,代碼來源:XmlUrlResolver

示例2: XmlCachingResolver

Class XmlCachingResolver
    Inherits XmlUrlResolver
    Dim enableHttpCaching As Boolean
    Public Shadows Credentials As ICredentials

    'resolve resources from cache (if possible) when enableHttpCaching is set to true
    'resolve resources from source when enableHttpcaching is set to false
    Public Sub New(ByVal enableHttpCaching As Boolean)
        Me.enableHttpCaching = enableHttpCaching
    End Sub

    Public Shadows Function GetEntity(ByVal absoluteUri As Uri, ByVal role As String, ByVal returnType As Type) As Object
        If absoluteUri = Nothing Then
            Throw New ArgumentNullException("absoluteUri")
        End If

        'resolve resources from cache (if possible)
        If absoluteUri.Scheme = "http" And enableHttpCaching And (returnType Is GetType(Nullable) Or returnType Is GetType(Stream)) Then
            Dim webReq As WebRequest = WebRequest.Create(absoluteUri)
            webReq.CachePolicy = New HttpRequestCachePolicy(HttpRequestCacheLevel.Default)
            If Not (Credentials Is Nothing) Then
                webReq.Credentials = Credentials
            End If
            Dim resp As WebResponse = webReq.GetResponse()
            Return resp.GetResponseStream()
            'otherwise use the default behavior of the XmlUrlResolver class (resolve resources from source)
        Else
            Return MyBase.GetEntity(absoluteUri, role, returnType)
        End If

    End Function
End Class
開發者ID:VB.NET開發者,項目名稱:System.Xml,代碼行數:32,代碼來源:XmlUrlResolver


注:本文中的System.Xml.XmlUrlResolver類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。