本文整理汇总了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