XmlTextReader.XmlResolver Propriedade

Definição

Define o XmlResolver usado para resolver referências de DTD.Sets the XmlResolver used for resolving DTD references.

public:
 property System::Xml::XmlResolver ^ XmlResolver {  void set(System::Xml::XmlResolver ^ value); };
public System.Xml.XmlResolver? XmlResolver { set; }
public System.Xml.XmlResolver XmlResolver { set; }
member this.XmlResolver : System.Xml.XmlResolver
Public Property XmlResolver As XmlResolver

Valor da propriedade

XmlResolver

O XmlResolver a ser usado.The XmlResolver to use. Se definido como null, os recursos externos não serão resolvidos.If set to null, external resources are not resolved.

Na versão 1,1 do .NET Framework, o chamador deve ser totalmente confiável para especificar um XmlResolver .In version 1.1 of the .NET Framework, the caller must be fully trusted in order to specify an XmlResolver.

Exemplos

O exemplo a seguir usa a XmlResolver propriedade para especificar as credenciais necessárias para acessar o arquivo em rede.The following example uses the XmlResolver property to specify the credentials necessary to access the networked file.

#using <System.dll>
#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
using namespace System::Net;
int main()
{
   
   // Create the reader.
   XmlTextReader^ reader = gcnew XmlTextReader( "http://myServer/data/books.xml" );
   
   // Supply the credentials necessary to access the Web server.
   XmlUrlResolver^ resolver = gcnew XmlUrlResolver;
   resolver->Credentials = CredentialCache::DefaultCredentials;
   reader->XmlResolver = resolver;
   
   // Parse the file.
   while ( reader->Read() )
   {
      
      // Do any additional processing here.
   }

   
   // Close the reader.
   reader->Close();
}

using System;
using System.IO;
using System.Xml;
using System.Net;

public class Sample {

  public static void Main() {

    // Create the reader.
    XmlTextReader reader = new XmlTextReader("http://myServer/data/books.xml");

    // Supply the credentials necessary to access the Web server.
    XmlUrlResolver resolver = new XmlUrlResolver();
    resolver.Credentials = CredentialCache.DefaultCredentials;
    reader.XmlResolver = resolver;

    // Parse the file.
    while (reader.Read()) {
       // Do any additional processing here.
    }

    // Close the reader.
    reader.Close();
  }
}
Imports System.IO
Imports System.Xml
Imports System.Net

public class Sample 

  public shared sub Main() 

    ' Create the reader.
    Dim reader as XmlTextReader = new XmlTextReader("http://myServer/data/books.xml")
   
    ' Supply the credentials necessary to access the Web server.
    Dim resolver as XmlUrlResolver = new XmlUrlResolver()
    resolver.Credentials = CredentialCache.DefaultCredentials
    reader.XmlResolver = resolver

    ' Parse the file.
    while (reader.Read()) 
       ' Do any additional processing here.
    end while           
  
    ' Close the reader.
    reader.Close()     
  
  end sub
end class

Comentários

Observação

A partir do .NET Framework 2,0, recomendamos que você crie XmlReader instâncias usando o XmlReader.Create método para aproveitar a nova funcionalidade.Starting with the .NET Framework 2.0, we recommend that you create XmlReader instances by using the XmlReader.Create method to take advantage of new functionality.

O leitor usa XmlResolver o para resolver o local do arquivo carregado no leitor e também para resolver referências de DTD.The reader uses XmlResolver to resolve the location of the file loaded into the reader and also to resolve DTD references. Por exemplo, se o XML incluísse a declaração DOCTYPE, <!DOCTYPE book SYSTEM book.dtd> o leitor resolverá esse arquivo externo e garantirá que o DTD esteja bem formado.For example, if your XML included the DOCTYPE declaration, <!DOCTYPE book SYSTEM book.dtd> the reader resolves this external file and ensures that the DTD is well-formed. O leitor não usa o DTD para validação.The reader does not use the DTD for validation.

Essa propriedade pode ser alterada a qualquer momento e entra em vigor na próxima operação de leitura.This property can be changed at any time and takes effect on the next read operation. Se essa propriedade for definida como null , quaisquer referências de DTD externas encontradas pelo leitor não serão resolvidas.If this property is set to null, any external DTD references encountered by the reader are not resolved.

Na versão 1,1 do .NET Framework, se essa propriedade não for definida, o nível de confiança do aplicativo determinará o comportamento padrão.In version 1.1 of the .NET Framework, if this property is not set, the trust level of the application determines the default behavior.

Fully trusted code: O leitor usa um padrão XmlUrlResolver sem credenciais de usuário.Fully trusted code: The reader uses a default XmlUrlResolver with no user credentials. Se a autenticação for necessária para acessar um recurso de rede, use a XmlResolver propriedade para especificar um XmlResolver com as credenciais necessárias.If authentication is required to access a network resource, use the XmlResolver property to specify an XmlResolver with the necessary credentials.

Semi-trusted code: A XmlResolver propriedade é definida como null .Semi-trusted code: The XmlResolver property is set to null. Os recursos externos não são resolvidos.External resources are not resolved.

Aplica-se a

Confira também