You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by "Dantzler, DeWayne C" <de...@boeing.com> on 2007/10/26 06:12:45 UTC

FW: How to load an external DTD using the Xerces Library

> Xerces has a method to enable/disable the loading of an external DTD
> 
> /** Set the 'Loading External DTD' flag
>       *
>       * This method allows users to enable or disable the loading of
> external DTD.
>       * When set to false, the parser will ignore any external DTD
> completely
>       * if the validationScheme is set to Val_Never.
>       *
>       * The parser's default state is: true.
>       *
>       * This flag is ignored if the validationScheme is set to
> Val_Always or Val_Auto.
>       *
>       * @param newState The value specifying whether external DTD
> should
>       *                 be loaded or not.
>       *
>       * @see #getLoadExternalDTD
>       * @see #setValidationScheme
>       */
>     void setLoadExternalDTD(const bool newState);
> 
> But, I can't seem to locate the actual method to load an external DTD.
> 
> 
> De Wayne Dantzler
> 

Re: How to get the Parser to recognize the setDisableDefaultEntityResolution option

Posted by David Bertoni <db...@apache.org>.
Dantzler, DeWayne C wrote:
> I'm trying to get the Parser to check only for well-formness and ignore
> external Entities. I've set the option to disable the default entity
> resolver and overridden the resovler to return NULL, but the Parser
> still attempts to open the DTD referenced in the document. 
Returning a null pointer tells the parser the EntityResolver instance did 
not try to resolve the entity.  Instead, return an InputSource instance 
that's empty.  An easy way to do that is to return a MemBufInputSource that 
has a length of 0.

Dave

How to get the Parser to recognize the setDisableDefaultEntityResolution option

Posted by "Dantzler, DeWayne C" <de...@boeing.com>.
I'm trying to get the Parser to check only for well-formness and ignore
external Entities. I've set the option to disable the default entity
resolver and overridden the resovler to return NULL, but the Parser
still attempts to open the DTD referenced in the document. 

Since the DTD is not local, the Parser reports::

	Parser Error Message: An exception occurred!
Type:RuntimeException, Message:Could not open DTD file

Code snippet:
	    /* This method gives users the option to not perform default
entity
	     * resolution.  If the user's resolveEntity method returns
NULL the
	     * parser will try to resolve the entity on its own.  When
this option
	     * is set to true, the parser will not attempt to resolve
the entity
	     * when the resolveEntity method returns NULL.
	     */
		_XmlDOMParser->setDisableDefaultEntityResolution(true);
		
		//turn off the features to allow validation by
Schema/DTD
	
_XmlDOMParser->setValidationScheme(_XmlDOMParser->Val_Never);//turn off
validation
		_XmlDOMParser->setDoSchema(false);//disable the parser's
schema processing.
	
_XmlDOMParser->setDisableDefaultEntityResolution(true);//disable default
entity resolution
		_XmlDOMParser->setSkipDTDValidation(true);

If no document type declaration, how to parse using an external DTD

Posted by "Dantzler, DeWayne C" <de...@boeing.com>.
I have an XML file that does not have a DTD reference in the file. (i.e
<!DOCTYPE records SYSTEM "some.xml file path">, but I want to validate
the XML against an external DTD using the Xerces library. I've tried the
setting below, but the parser does not recognize or load the specified
DTD. The parser reports errors for 'ALL' element tags as undefined!! The
Entity Resolver handler is never called by the parser!! How do I get the
parser to 'load' and 'use' an external DTD given no DTD reference is
specified in the XML file? 
 
	*Override the default Entity Resolver and use mine
		_XmlDOMParser->setEntityResolver(resolver);

	
_XmlDOMParser->setValidationScheme(_XmlDOMParser->Val_Always);
		_XmlDOMParser->setDoSchema(false);

      * This method allows users to enable or disable the loading of
external DTD.
      * When set to false, the parser will ignore any external DTD
completely
      * if the validationScheme is set to Val_Never.		
	
		_XmlDOMParser->setLoadExternalDTD(true);
    
      * Preparse schema grammar (XML Schema, DTD, etc.) via a file path
or URL
      *
      * This method invokes the preparsing process on a schema grammar
XML
      * file specified by the file path parameter. If the 'toCache' flag
      * is enabled, the parser will cache the grammars for re-use. If a
grammar
      * key is found in the pool, no caching of any grammar will take
place.

		_XmlDOMParser->loadGrammar(dtd, Grammar::DTDGrammarType,
false);
		_XmlDOMParser->setSkipDTDValidation(false);

      * This method allows users to enable or disable the use of cached
      * grammars.  When set to true, the parser will use the cached
grammar,
      * instead of building the grammar from scratch, to validate XML
      * documents.

		_XmlDOMParser->useCachedGrammarInParse(true);
		_XmlDOMParser->parse(xmlDoc2Parse);	

Re: FW: How to load an external DTD using the Xerces Library

Posted by David Cargill <ca...@ca.ibm.com>.
Hi,
You can try the loadGrammar method to load an external dtd.  It is
available on most of the parsers.  I can't remember using it myself so not
sure how well it works...

Regards,
David


                                                                           
             "Dantzler,                                                    
             DeWayne C"                                                    
             <dewayne.c.dantzl                                          To 
             er@boeing.com>            <c-...@xerces.apache.org>         
                                                                        cc 
             10/26/2007 12:12                                              
             AM                                                    Subject 
                                       FW: How to load an external DTD     
                                       using the Xerces Library            
             Please respond to                                             
             c-users@xerces.ap                                             
                 ache.org                                                  
                                                                           
                                                                           
                                                                           





> Xerces has a method to enable/disable the loading of an external DTD
>
> /** Set the 'Loading External DTD' flag
>       *
>       * This method allows users to enable or disable the loading of
> external DTD.
>       * When set to false, the parser will ignore any external DTD
> completely
>       * if the validationScheme is set to Val_Never.
>       *
>       * The parser's default state is: true.
>       *
>       * This flag is ignored if the validationScheme is set to
> Val_Always or Val_Auto.
>       *
>       * @param newState The value specifying whether external DTD
> should
>       *                 be loaded or not.
>       *
>       * @see #getLoadExternalDTD
>       * @see #setValidationScheme
>       */
>     void setLoadExternalDTD(const bool newState);
>
> But, I can't seem to locate the actual method to load an external DTD.
>
>
> De Wayne Dantzler
>