XmlUrlResolver.GetEntity(Uri, String, Type) Metoda

Definicja

Mapy identyfikator URI do obiektu zawierającego rzeczywisty zasób.

public:
 override System::Object ^ GetEntity(Uri ^ absoluteUri, System::String ^ role, Type ^ ofObjectToReturn);
public override object? GetEntity (Uri absoluteUri, string? role, Type? ofObjectToReturn);
public override object GetEntity (Uri absoluteUri, string role, Type ofObjectToReturn);
override this.GetEntity : Uri * string * Type -> obj
Public Overrides Function GetEntity (absoluteUri As Uri, role As String, ofObjectToReturn As Type) As Object

Parametry

absoluteUri
Uri

Identyfikator URI zwrócony z ResolveUri(Uri, String)elementu .

role
String

Obecnie nie jest używany.

ofObjectToReturn
Type

Typ obiektu, który będzie zwracany. Bieżąca implementacja zwraca Stream tylko obiekty.

Zwraca

Object

Obiekt strumienia lub null jeśli określono typ inny niż strumień.

Wyjątki

ofObjectToReturn nie jest ani null typem Stream .

Określony identyfikator URI nie jest bezwzględnym identyfikatorem URI.

absoluteUri to null.

Wystąpił błąd środowiska uruchomieniowego (na przykład przerwane połączenie z serwerem).

Przykłady

W poniższym przykładzie przedstawiono GetEntity metody i ResolveUri .

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

using namespace System;
using namespace System::IO;
using namespace System::Xml;

int main()
{
   XmlUrlResolver^ resolver = gcnew XmlUrlResolver;
   Uri^ baseUri = gcnew Uri( "http://servername/tmp/test.xsl" );
   Uri^ fulluri = resolver->ResolveUri( baseUri, "includefile.xsl" );

   // Get a stream object containing the XSL file
   Stream^ s = dynamic_cast<Stream^>(resolver->GetEntity( fulluri, nullptr, Stream::typeid ));

   // Read the stream object displaying the contents of the XSL file
   XmlTextReader^ reader = gcnew XmlTextReader( s );
   while ( reader->Read() )
   {
      Console::WriteLine( reader->ReadOuterXml() );
   }
}
using System;
using System.IO;
using System.Xml;

 public class Sample
 {

   public static void Main()
   {
       XmlUrlResolver resolver = new XmlUrlResolver();

       Uri baseUri = new Uri ("http://servername/tmp/test.xsl");

       Uri fulluri=resolver.ResolveUri(baseUri, "includefile.xsl");

       // Get a stream object containing the XSL file
       Stream s=(Stream)resolver.GetEntity(fulluri, null, typeof(Stream));

       // Read the stream object displaying the contents of the XSL file
       XmlTextReader reader = new XmlTextReader(s);
       while (reader.Read())
       {
          Console.WriteLine(reader.ReadOuterXml());
       }
   }
}
Imports System.IO
Imports System.Xml

Public Class Sample
    
  Public Shared Sub Main()

     Dim resolver As New XmlUrlResolver()
     Dim baseUri As New Uri("http://servername/tmp/test.xsl")
     Dim fulluri As Uri = resolver.ResolveUri(baseUri, "includefile.xsl")
            
     ' Get a stream object containing the XSL file
     Dim s As Stream = CType(resolver.GetEntity(fulluri, Nothing, GetType(Stream)), Stream)
            
     ' Read the stream object displaying the contents of the XSL file
     Dim reader As New XmlTextReader(s)
     While reader.Read()
        Console.WriteLine(reader.ReadOuterXml())
     End While
        
  End Sub
End Class

Uwagi

Ta metoda jest używana, gdy obiekt wywołujący chce zamapować dany identyfikator URI na obiekt zawierający zasób, który reprezentuje identyfikator URI.

Aby uzyskać asynchroniczną wersję tej metody, zobacz GetEntityAsync.

Ważne

Aplikacja może ograniczyć ryzyko odmowy usługi pamięci do GetEntity metody, implementując IStream IStream , aby ograniczyć liczbę odczytanych bajtów. Pomaga to chronić przed sytuacjami, w których złośliwy kod próbuje przekazać nieskończony strumień bajtów do GetEntity metody.

Dotyczy

Zobacz też