Robert William Vesterman wrote:
I am using Xerces-C SAX2 to parse some documents that I write. When I write
them, I would like to include a reference to an appropriate DTD in a
doctypedecl. However, I want to do so basically for the purposes of people
looking at the documents, or trying to build their own. I do *not* want
Xerces to pay attention to the DTD while parsing the XML, and I *especially*
do not want Xerces to try to fetch the DTD for any purpose (this application
will be running on non-internet enabled machines, and speed is of the
essence).
So, essentially, I would like to know if it's possible to set up Xerces-C
SAX2 to ignore a well-formed doctypedecl, and if so, how.
You can use the EntityResolver mechanism to control external entities.
Whenever the parser needs an external entity, it will call your
implementation of EntityResolver. If you return a null pointer, the
parser will attempt to dereference the system ID of the entity. If you
return a InputSource instance, it will use that to read the entity. You
can always return an InputSource that is "empty" if you want the DTD to
be empty.
However, if the instance document requires the DTD, because it contains
references to other entities defined in the DTD, you cannot return an
"empty" InputSource. Note also that you can change the content of the
document by not including the DTD. For example, the DTD might specify
default attributes, which would not be added if you don't let the parser
read the DTD.
I think if you search the mailing list archives for "EntityResolver",
you'll find more information.
Dave