开发者

How to control DTD reading with .NET?

开发者 https://www.devze.com 2022-12-14 02:33 出处:网络
A C# program of ours reads an XML file. The XML file has standalone=\'no\' header. The DOCTYPE used to look like:

A C# program of ours reads an XML file. The XML file has standalone='no' header.

The DOCTYPE used to look like:

<!DOCTYPE foo SYSTEM "silly.dtd">

where silly.dtd is not sitting right there next to the file.

For various reasons, I changed this to

<!DOCTYPE foo PUBLIC "-//Some Public Id" "urn:outerspace:silly.dtd">

I expected nothing to change, since the DTD could n开发者_开发知识库ot be opened as './silly.dtd' before, and it can't be opened at 'urn:outerspace:silly.dtd' now. The only difference was that a catalog resolver wouldn't have to worry about the absolutization of the system ID.

Imagine my surprise to get an exception from the .NET runtime, apparently trying to open the DTD at the urn: address.

Can some kind person direct me to a recipe to tell .NET to just quietly give up in this case? I know how to do this in Java, but in .NET I'm a bit lost.


Implement your own XmlResolver to handle this (you could just inherit from XmlUrlResolver), then plug it into a XmlTextReader and pass the reader to the XmlDocument.


The reader will not attempt to access the dtd if you have the following properties: .ProhibitDtd=false; .XmlResolver=null;

0

精彩评论

暂无评论...
验证码 换一张
取 消