XmlUrlResolver.GetEntity(Uri, String, Type) XmlUrlResolver.GetEntity(Uri, String, Type) XmlUrlResolver.GetEntity(Uri, String, Type) XmlUrlResolver.GetEntity(Uri, String, Type) Method

Definition

Maps a URI to an object that contains the actual resource.

public:
 override System::Object ^ GetEntity(Uri ^ absoluteUri, System::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

Parameters

absoluteUri
Uri Uri Uri Uri

The URI returned from ResolveUri(Uri, String).

role
String String String String

Currently not used.

ofObjectToReturn
Type Type Type Type

The type of object to return. The current implementation only returns Stream objects.

Returns

A stream object or null if a type other than stream is specified.

Exceptions

ofObjectToReturn is neither null nor a Stream type.

There is a runtime error (for example, an interrupted server connection).

Examples

The following example demonstrates the GetEntity and ResolveUri methods.

#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
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 'New 
End Class 'Sample

Remarks

This method is used when the caller wants to map a given URI to an object that contains the resource that the URI represents.

For the asynchronous version of this method, see GetEntityAsync.

Important

Your application can mitigate memory denial of service threats to the GetEntity method by implementing IStream IStream to limit the number of bytes read. This helps guard against situations where malicious code attempts to pass an infinite stream of bytes to the GetEntity method.

Applies to

See also