At 12.45 12/07/01 +0200, you wrote:
>Hi all,
>
>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?

The code I use for this task is this (but I use it to validate XML files 
that don't have a DOCTYPE entry, so I am not sure it works if there is one):

XMLByte* dummyXML="<?xml version=\"1.0\"?><!DOCTYPE myDtdRoot SYSTEM 
\"MyFixedDTD.dtd\"><myDtdRoot/>";
MemBufInputSource inputSource(dummyXML,strlen(dummyXML),"dummy",false);
SAXParser sp;
sp.setDoValidation(true);
sp.parse(inputSource);

// now, reuse the validator and parse the new doc
FileInputSource inputSource2("somefile.xml");
sp.parse(inputSource2, true);

Hope this code is really working (as I removed a lot of extra stuff to get 
the core of the routine) and it helps you,

Alberto

-------------------------------
Alberto Massari
eXcelon Corp.
http://www.StylusStudio.com


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to