Frank Zhou wrote:
Hi All,

I am using Xerces-c 2.7.  I am having a problem
validating XML against a given DTD (a string).

I am using SAX2XMLReader and using loadGrammar(...) to
load the DTD. My code is something like this:

    SAX2XMLReader* parser =
XMLReaderFactory::createXMLReader();
    parser->setFeature(XMLUni::fgSAX2CoreValidation,
m_bValidate);
    parser->setFeature(XMLUni::fgXercesDynamic, true);

    parser->loagGrammar(DTDInputSource,
Grammar::DTDGrammarType);
parser->setErrorHandler(errorHandler);
    parser->setContentHandler(contentHandler);

    parser->parse(XMLinputsource);

I noticed that the validation is not happening,
invalid xml gets parsed without problem. However, if I
don't use loadGrammar(...), instead, I embedded the
dtd content into XML input using <!DOCTYPE ... ]>,
then the validation happens correctly.
Do I need to do some special settings? any problem
with loadGrammar(...)?

I believe you need to set the feature "use cached grammar in parse:"

http://xml.apache.org/xerces-c/program-sax2.html#use-cached

Not that if you enable the feature to cache the grammar from the parse, this feature is automatically enabled:

http://xml.apache.org/xerces-c/program-sax2.html#cache-grammar

Dave

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

Reply via email to