views:

339

answers:

1

I've written a class extending XmlUrlResolver to resolve references to public identifiers in XML documents. For example, when an XML document starts with:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE chapter PUBLIC "-//Custom//EN" "custom.dtd">

The public identifier "-//Custom/EN" is passed to the relativeURI parameter of my overriden ResolveUri() method, and resolved to the actual DTD location on disk. That works correctly.

The problem occurs when there is an entity reference inside the DTD itself. For example:

<!ENTITY % tablemodel
  PUBLIC "-//OASIS//DTD XML Exchange Table Model 19990315//EN"
  "soextblx.dtd">

In this case, the system identifier "soextblx.dtd" is passed to ResolveUri() instead of the public identifier "-//OASIS//DTD XML Exchange Table Model 19990315//EN".

Is there any way to accomplish this? Overriding GetEntity() does not seem to work, either, because it is also passed the system identifier.

+1  A: 

In the current implementation the public identifier is not used when resolving an external identifier. Your option is to use the exception as a catch and then string validate the public id (however, this solution is not elegant and is cludgy). Though, it would work....

Of course (this would also require that you know the public id or at least a portion of the string), so that you could use the getEntity().

I searched online for a reference that identifies this:

http://bytes.com/topic/net/answers/172597-xmlresolver-parameter-entity-problem

Hopefully, this helps.

Joe Garrett