[Expat-discuss] Looking for sample code using ExternalEntityRefHandler

Josh Martin Josh.Martin@abq.sc.philips.com
Wed Jun 5 17:35:02 2002


Since I'm not sure that you've had a chance to read this, I'll just quote the 
documentation for the XML_ExternalEntityRefHandler handler.  If you'd like more, 
or different information, let me know.  If, however, you do understand the 
meaning of the properties that are passed to the handler, but are not sure what 
should be done with them, I'll discuss that after the documentation block.

 - Josh Martin

****************************************

XML_SetExternalEntityRefHandler(XML_Parser p,
                                      XML_ExternalEntityRefHandler hndl)

      typedef int
      (*XML_ExternalEntityRefHandler)(XML_Parser p,
                                      const XML_Char *context,
                                      const XML_Char *base,
                                      const XML_Char *systemId,
                                      const XML_Char *publicId);

        Set an external entity reference handler. This handler is also called 
for processing an external DTD subset if parameter entity parsing is in effect. 
(See XML_SetParamEntityParsing.)

        The base parameter is the base to use for relative system identifiers. 
It is set by XML_SetBase and may be null. The public id parameter is the public 
id given in the entity declaration and may be null. The system id is the system 
identifier specified in the entity declaration and is never null.

        There are a couple of ways in which this handler differs from others. 
First, this handler returns an integer. A non-zero value should be returned for 
successful handling of the external entity reference. Returning a zero indicates 
failure, and causes the calling parser to return an 
XML_ERROR_EXTERNAL_ENTITY_HANDLING error.

        Second, instead of having userData as its first argument, it receives 
the parser that encountered the entity reference. This, along with the context 
parameter, may be used as arguments to a call to XML_ExternalEntityParserCreate. 
Using the returned parser, the body of the external entity can be recursively 
parsed.

        Since this handler may be called recursively, it should not be saving 
information into global or static variables.
        
****************************************

The handler should open the file that is referenced by the 'base' and 'systemId' 
properties, and create a new XML_Parser object from the old one by calling 
XML_ExternalEntityParserCreate with the 'p' and 'context' properties and the 
desired encoding mode.  This new parser will inherit state information such as 
handlers, user data, and namespace processing from the old parser.  It should 
then proceed to parse this new parser buffer just like any other buffer, using 
the XML_Parse or XML_ParseBuffer methods.
 
> Hi,
> I'm using the expat parser for a Pocket PC app developed using MS emBedded C++ 
and the std
> XML_ParserCreate doesn't work very well for the following tag:
> <Description>Anything containing encoded data such as 
&amp;&lt;96D&gt;Accepted</Description>
> 
> I beleive I need to set entity parsing to XML_PARAM_ENTITY_PARSING_NEVER .  
The function is not
> available to me which probably means my compilation of expat is missing 
something.  It's not clear to
> me what should be in the ExternalEntityRefHandler callback function.
> 
> Any help is appreciated.
> 
> Thanks
> Tom
> 
> 	g GE Global Research Center
> 	
> 
________________________________________________________________________________
_____________________
> __________________________________________________________
> 	Tom St.Louis
> 	Computer Scientist
> 	Advanced Computing Technologies
> 	One Research Circle, K1-5B32	
> 	Niskayuna, NY  12309
> 	8*833-4900
> 	stlouis@crd.ge.com
> 
> 
> _______________________________________________________________
> 
> Don't miss the 2002 Sprint PCS Application Developer's Conference
> August 25-28 in Las Vegas -- http://devcon.sprintpcs.com/adp/index.cfm
> 
> _______________________________________________
> Expat-discuss mailing list
> Expat-discuss@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/expat-discuss