本文整理匯總了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)
示例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