XmlUrlResolver.GetEntity(Uri, String, Type) Metoda

Definice

Mapy identifikátor URI k objektu, který obsahuje skutečný prostředek.

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

Identifikátor URI vrácený z ResolveUri(Uri, String).

role
String

Aktuálně se nepoužívá.

ofObjectToReturn
Type

Typ objektu, který chcete vrátit. Aktuální implementace vrací Stream pouze objekty.

Návraty

Object

Objekt streamu nebo null pokud je zadán jiný typ než datový proud.

Výjimky

ofObjectToReturn není ani null Stream typ.

Zadaný identifikátor URI není absolutní identifikátor URI.

absoluteUri je null.

Došlo k chybě za běhu (například přerušené připojení serveru).

Příklady

Následující příklad ukazuje GetEntity a ResolveUri metody.

#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

Poznámky

Tato metoda se používá, když volající chce mapovat daný identifikátor URI na objekt, který obsahuje prostředek, který představuje identifikátor URI.

Asynchronní verze této metody naleznete v tématu GetEntityAsync.

Důležité

Vaše aplikace může zmírnit útoky GetEntity na dostupnost služby paměti implementací IStreamu IStream , aby omezila počet čtení bajtů. To pomáhá chránit před situacemi, kdy se škodlivý kód pokusí předat do metody nekonečný proud bajtů GetEntity .

Platí pro

Viz také