XmlResolver 类
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
解析由统一资源标识符(URI)命名的外部 XML 资源。
public ref class XmlResolver abstract
C#
public abstract class XmlResolver
type XmlResolver = class
Public MustInherit Class XmlResolver
- 继承
-
XmlResolver
- 派生
以下示例使用默认凭据创建 XmlUrlResolver。 XmlReader 用于读取和显示生成的数据流。
C#
using System;
using System.Xml;
using System.IO;
class Example
{
static void Main()
{
// Create an XmlUrlResolver with default credentials.
XmlUrlResolver resolver = new XmlUrlResolver();
resolver.Credentials = System.Net.CredentialCache.DefaultCredentials;
// Point the resolver at the desired resource and resolve as a stream.
Uri baseUri = new Uri("http://serverName/");
Uri fulluri = resolver.ResolveUri(baseUri, "fileName.xml");
Stream s = (Stream)resolver.GetEntity(fulluri, null, typeof(Stream));
// Create the reader with the resolved stream and display the data.
XmlReader reader = XmlReader.Create(s);
while (reader.Read())
{
Console.WriteLine(reader.ReadOuterXml());
}
}
}
Imports System.Xml
Imports System.IO
Module Module1
Sub Main()
' Create an XmlUrlResolver with default credentials.
Dim resolver As New XmlUrlResolver()
resolver.Credentials = System.Net.CredentialCache.DefaultCredentials
' Point the resolver at the desired resource and resolve as a stream.
Dim baseUri As New Uri("http://serverName/")
Dim fulluri As Uri = resolver.ResolveUri(baseUri, "fileName.xml")
Dim s As Stream = CType(resolver.GetEntity(fulluri, Nothing, GetType(Stream)), Stream)
' Create the reader with the resolved stream and display the data.
Dim reader As XmlReader = XmlReader.Create(s)
While reader.Read()
Console.WriteLine(reader.ReadOuterXml())
End While
End Sub
End Module
有关此 API 的详细信息,请参阅 xmlResolver
Xml |
初始化 XmlResolver 类的新实例。 |
Credentials |
在派生类中重写时,设置用于对 Web 请求进行身份验证的凭据。 |
File |
获取仅解析文件系统 URI 的 XML 解析程序。 |
Throwing |
获取禁止实体解析的 XML 解析程序。 |
Equals(Object) |
确定指定的对象是否等于当前对象。 (继承自 Object) |
Get |
在派生类中重写时,将 URI 映射到包含实际资源的对象。 |
Get |
将 URI 异步映射到包含实际资源的对象。 |
Get |
用作默认哈希函数。 (继承自 Object) |
Get |
获取当前实例的 Type。 (继承自 Object) |
Memberwise |
创建当前 Object的浅表副本。 (继承自 Object) |
Resolve |
在派生类中重写时,从基 URI 和相对 URI 解析绝对 URI。 |
Supports |
使解析程序能够返回除 Stream以外的类型。 |
To |
返回一个表示当前对象的字符串。 (继承自 Object) |
产品 | 版本 |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |