At 12:45 PM 12/07/2001 +0200, Evert Haasdijk wrote:
>I've got an application where I use XML documents that _must_ adhere to a
>certain, known, DTD.
>What I'd like to be able to do is force my DOMParser (or its Validator, or
>whatever) to always use a DTDValidator with that DTD to validate documents,
>even if their DOCTYPE is missing or says they're of a different type (if the
>document is of a different type, I can't successfully use it)
>I've looked closely at DTDValidator, but even creating my own validator
>won't help, because its scanDocTypeDecl() method will only be called if a
><DOCTYPE entry is found.
>Is there any way of achieving this?
I'm not sure there's a way to do what you say. However, the approach we use
where we need to force 1) a specific DTD and 2) validation is:
1) Use a DOCTYPE PUBLIC definition which uses a "public" identifier for the DTD
you wish to use.
2) Check the doctype recorded in the DOM tree after the parse. If it's not
correct, we turf it.
3) We attach an entity resolver to the parser that ignores all requests except
for our public identifier from step 1). We then return our 'known' DTD.
This approach may be sufficient for your needs.
- Andrew
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]