Ion Vasilian wrote:
> Hi,
>
> Here's the code that should do the trick:
>
> class DummyResolver : XmlUrlResolver {
> ...
> public override object GetEntity(Uri absoluteUri, string role, Type
> ofObjectToReturn) {
> if (absoluteUri != null && absoluteUri.AbsoluteUri == "<whatever you want
> to override>") {
> if (ofObjectToReturn == null || ofObjectToReturn ==
> typeof(System.IO.Stream)) {
> return Stream.Null;
> }
> }
> return base.GetEntity(absoluteUri, role, ofObjectToReturn);
> }
>
> Regards,
> Ion
>
> "Chris" <chrismc912@hotmail.com> wrote in message
> news:OsDZR4$LFHA.3632@TK2MSFTNGP10.phx.gbl...
>
>>Hi Ion,
>>thanks a lot for your reply. As I am quite new to .net I am not sure
>>what type of System.IO.Stream object to retun. Can you give me an
>>example of an empty stream?
>>
>>Thanks,
>>Chris
>>
>>Ion Vasilian wrote:
>>
>>>Hi,
>>>
>>>Instead of returning 'null' from ResolveUri(), return an empty stream
>>>from GetEntity() whenever you get a resolution request for the known
>>>'bad' uris. Regards,
>>>
>>>Ion
>>>
>>>"Chris" <chrismc912@hotmail.com> wrote in message
>>>news:OJDI$1vLFHA.1884@TK2MSFTNGP15.phx.gbl...
>>>
>>>
>>>>Thanks for your reply,
>>>>using your suggested method seems the right way.
>>>>Doing so, I get an Exception "object reference not set to an instance of
>>>>an object" as soon as I 'return null' in the overridden method.
>>>>The ResolveUri function is also often called with the document parsed,
>>>>but with an empty baseUri. So I think that the baseUri is only != null
>>>>when the parser tries to resolve a link. So I tried:
>>>>
>>>>if( baseUri != null )
>>>> return null;
>>>>else
>>>> return base.ResolveUri( baseUri, relativeUri );
>>>>
>>>>But as soon as I return null I get the above mentioned error.
>>>>Any suggestions?
>>>>Thanks,
>>>>Chris
>>>>
>>>>Martin Honnen wrote:
>>>>
>>>>
>>>>>Chris wrote:
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>>Are there any switches in XmlDocument that I can use to ignore the
>
> dtd?
>
>>>>>
>>>>>You would need to assign an XmlResolver that returns null for any URL
>>>>>passed in e.g. (pseudo code)
>>>>>
>>>>>class DummyResolver : XmlUrlResolver {
>>>>> public override Uri ResolveUri (Uri baseUri, String relativeUri) {
>>>>> return null;
>>>>> }
>>>>>}
>>>>>
>>>>>XmlDocument xmlDocument = new XmlDocument();
>>>>>xmlDocument.XmlResolver = new DummyResolver();
>>>>>
>>>>>xmlDocument.Load(@"whatever.xml");
>>>>>
>>>>>But you need to be aware that a DTD is not only necessary for
>
> validation
>
>>>>>but can also be needed to resolve entity references.
>>>>>
>>>>>And the behavior of XmlDocument and its XmlResolver depends on
>
> different
>
>>>>>factors, see
>>>>>
>>>
>>>
> <
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html
>
>>>/frlrfSystemXmlXmlDocumentClassXmlResolverTopic.asp>
>>>
>>>
>