I am trying to port an application from xerces 1.5.2 to 2.1, and I have some trouble with replacing the “reuseGrammar” flag that was previously available. We are trying to parse a DTD in memory and then to use this DTD to validate our documents.

 

The following used to work fine with v1.5.2:

 

            #define AgCPluginsXmlDtd                                            \

                "<?xml version = \"1.0\" standalone = \"yes\"?>             "   \

                "<!DOCTYPE AGIRegistry [                                    "   \

                "   <!ELEMENT AGIRegistry (CategoryRegistry?, NoCategory?)> "   \

                "]>                                                         "   \

 

            static char *g_sDoc =

            "<?xml version = \"1.0\"?>                                       \n"

            "<AGIRegistry>                                                   \n"

            "</AGIRegistry>                                                  \n"

            ;

 

            void main()

            {

                XMLPlatformUtils::Initialize();

           

                CAgSAXHandler handler;

 

                SAXParser parser;

                parser.setErrorHandler(&handler);

                parser.setValidationScheme(SAXParser::Val_Always);

                parser.setDoNamespaces(false);

 

                CAgMemBufInputSource dtdInputSource(AgCPluginsXmlDtd);

                parser.parse(dtdInputSource);

 

                CAgMemBufInputSource docInputSource(g_sDoc);

                parser.parse(docInputSource, true); // <<<<< reuseGrammar

 

                XMLPlatformUtils::Terminate();

            }

 

Now when I try to use the loadGrammar replacement:

 

            void main()

            {

                XMLPlatformUtils::Initialize();

 

                CAgSAXHandler handler;

 

                SAXParser parser;

                parser.setErrorHandler(&handler);

                parser.setValidationScheme(SAXParser::Val_Always);

                parser.setDoNamespaces(false);

 

                CAgMemBufInputSource dtdInputSource(AgCPluginsXmlDtd);

                parser.loadGrammar(dtdInputSource, Grammar::DTDGrammarType, true);

                parser.useCachedGrammarInParse(true);

 

                CAgMemBufInputSource docInputSource(g_sDoc);

                parser.parse(docInputSource);

 

                XMLPlatformUtils::Terminate();

            }

 

I get the following error:

 

            ERROR : XML Parser - Line: 2, char 13

            Unknown element 'AGIRegistry'

 

The DTD does not seem to be cached for the second parsing. What am I doing worng?

 

Thanks,

Sylvain

Reply via email to